Function pdqselect::select [−][src]
pub fn select<T>(v: &mut [T], k: usize) where
T: Ord,
Partially sorts a slice and puts the k
th smallest item in place.
This sort is in-place, unstable, and O(n log n)
worst-case.
The implementation is based on Orson Peters’ pattern-defeating quickselect.
Examples
let mut v = [-5, 4, 1, -3, 2]; let k = 2; pdqselect::select(&mut v, k); assert!(v[..k].iter().all(|&x| x <= v[k])); assert!(v[k+1..].iter().all(|&x| x >= v[k]));