[][src]Function floydrivest::nth_element

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

Moves the n-th element of the given Vector in the n-th position by using the Floyd-Rivest algorithm with linear time complexity.

Similar to its c++ counterpart.

Examples

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

assert_eq!(v[3], 7);

Panics

if nth_el is out of bounds.