Back to course home
0% completed
Vote For New Content
Bug in findMedian()
Aditya Bhave
Sep 27, 2024
If any of the heaps is empty, calling top() on them is undefined behavior. Consider changing the code like this
if (minHeap.empty()) { return maxHeap.empty() ? 0 : maxHeap.top(); } if (maxHeap.size() == minHeap.size()) { return maxHeap.top() / 2.0 + minHeap.top() / 2.0; } return maxHeap.top(); }
0
0
Comments
Comments
On this page