[][src]Function adqselect::nth_element

pub fn nth_element<T, F>(v: &mut [T], nth_el: usize, cmp: &mut F) where
    F: FnMut(&T, &T) -> Ordering

Moves the n-th element of the given Vector in the n-th position by using the adaptive quickselect algorithm by Andrei Alexandrescu.

Similar to its c++ counterpart.

Examples

let mut v = vec![10, 7, 9, 7, 2, 8, 8, 1, 9, 4];
adqselect::nth_element(&mut v, 3, &mut Ord::cmp);

assert_eq!(v[3], 7);

Panics

if nth_el is out of bounds.