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()); } }
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()); } }