Exemplo n.º 1
0
 void MergePairs(List <PairingHeap <T> > l)
 {
     if (l.Count == 0)
     {
         return;
     }
     else if (l.Count == 1)
     {
         if (root == null)
         {
             root = l[0].root;
         }
         else
         {
             root.item     = l[0].root.item;
             root.priority = l[0].root.priority;
         }
         children = l[0].children;
     }
     else
     {
         PairingHeap <T> aux = new PairingHeap <T>();
         aux.Merge(l[0]);
         aux.Merge(l[1]);
         PairingHeap <T> aux2 = new PairingHeap <T>();
         aux2.MergePairs(l.GetRange(2, l.Count - 2));
         aux.Merge(aux2);
         if (root == null)
         {
             root = aux.root;
         }
         else
         {
             root.item     = aux.root.item;
             root.priority = aux.root.priority;
         }
         children = aux.children;
     }
 }