Created
July 30, 2012 23:01
-
-
Save puneetlakhina/3211604 to your computer and use it in GitHub Desktop.
Get median from a list
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 getMedian(List<? extends Number> values) { | |
if(values.size() % 2 != 0) { | |
return values.get(values.size()/2).doubleValue(); | |
} else { | |
return (values.get((values.size()/2) - 1).doubleValue() + values.get(values.size()/2).doubleValue())/2; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment