예제 #1
0
        private void Balance()
        {
            if (!LowerHeap.IsEmpty && !UpperHeap.IsEmpty && LowerHeap.Peek() > UpperHeap.Peek())
            {
                int lowerHead = LowerHeap.Poll();
                int upperHead = UpperHeap.Poll();

                LowerHeap.Add(upperHead);
                UpperHeap.Add(lowerHead);
            }
        }
예제 #2
0
 public decimal GetMedian()
 {
     if (Length % 2 != 0)
     {
         return(UpperHeap.Peek());
     }
     else
     {
         return(((decimal)(UpperHeap.Peek() + LowerHeap.Peek())) / 2);
     }
 }