Esempio n. 1
0
        /// <summary> Swaps t's two children.</summary>
        private static void  swapChildren(LeftHeapNode t)
        {
            LeftHeapNode tmp = t.left;

            t.left  = t.right;
            t.right = tmp;
        }
Esempio n. 2
0
 internal LeftHeapNode(Comparable theElement, LeftHeapNode lt, LeftHeapNode rt)
 {
     element = theElement;
     left    = lt;
     right   = rt;
     npl     = 0;
 }
Esempio n. 3
0
 /// <summary> Internal static method to merge two roots.
 /// Assumes trees are not empty, and h1's root contains smallest item.
 /// </summary>
 private static LeftHeapNode merge1(LeftHeapNode h1, LeftHeapNode h2)
 {
     if (h1.left == null)
     {
         // Single node
         h1.left = h2;
     }
     // Other fields in h1 already accurate
     else
     {
         h1.right = merge(h1.right, h2);
         if (h1.left.npl < h1.right.npl)
         {
             swapChildren(h1);
         }
         h1.npl = h1.right.npl + 1;
     }
     return(h1);
 }
Esempio n. 4
0
 /// <summary> Internal static method to merge two roots.
 /// Deals with deviant cases and calls recursive merge1.
 /// </summary>
 private static LeftHeapNode merge(LeftHeapNode h1, LeftHeapNode h2)
 {
     if (h1 == null)
     {
         return(h2);
     }
     if (h2 == null)
     {
         return(h1);
     }
     if (h1.element.compareTo(h2.element) < 0)
     {
         return(merge1(h1, h2));
     }
     else
     {
         return(merge1(h2, h1));
     }
 }