Ejemplo n.º 1
0
 /// <summary>
 /// Helper method to balance heaps after each addition.
 /// </summary>
 /// <param name="lowerHeap"></param>
 /// <param name="upperHeap"></param>
 public static void Balance(MaxHeap lowerHeap, Heap upperHeap)
 {
     while (lowerHeap.Size > 0 && upperHeap.Size > 0 && lowerHeap.Peek() > upperHeap.Peek())
     {
         int lowHead  = lowerHeap.Poll();
         int highHead = upperHeap.Poll();
         upperHeap.Add(lowHead);
         lowerHeap.Add(highHead);
     }
 }