Ejemplo n.º 1
0
 static void ReBalance(MinHeap min, MaxHeap max)
 {
     if (min.Length() - max.Length() >= 2)
     {
         max.Add(min.Poll());
     }
     else if (max.Length() - min.Length() >= 2)
     {
         min.Add(max.Poll());
     }
 }
Ejemplo n.º 2
0
 static decimal GetMedian(MinHeap min, MaxHeap max)
 {
     if (min.Length() == max.Length())
     {
         return(Decimal.Divide(min.Peek() + max.Peek(), 2));
     }
     else if (min.Length() > max.Length())
     {
         return(min.Peek());
     }
     else
     {
         return(max.Peek());
     }
 }