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); } }
public decimal GetMedian() { if (Length % 2 != 0) { return(UpperHeap.Peek()); } else { return(((decimal)(UpperHeap.Peek() + LowerHeap.Peek())) / 2); } }