Created
April 6, 2013 21:35
-
-
Save ktraff/5327718 to your computer and use it in GitHub Desktop.
maintain the median with heaps 3
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public double findMedian(int[] arr) | |
{ | |
double median = Integer.MAX_VALUE; | |
for(int i=0;i<arr.length;i++) | |
{ | |
adjustHeaps(median); | |
if(arr[i] <= median) | |
{ | |
maxHeap.add(arr[i]); | |
} | |
else minHeap.add(arr[i]); | |
median = getMedian(); | |
} | |
return median; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment