[−][src]Function mememo::median
pub fn median(numbers: &Vec<i32>) -> Median
Calculates the median of the elements in the given vector.
Example
For a vector with an odd number of elements, the value of the middle element will be returned:
let numbers = vec![1, 2, 3, 4, 5]; match mememo::median(&numbers) { mememo::MiddleSingle(got) => assert_eq!(3, got), _ => panic!("wrong median calculation"), }
For a vector with an even number of elements, the mean of the two middle elements will be calculated:
let numbers = vec![1, 2, 3, 4]; match mememo::median(&numbers) { mememo::MiddleTwoMean(got) => assert_eq!(2.5, got), _ => panic!("wrong median calculation"), };