std-method

slice::select_nth_unstable

Partition around the element that would occupy index in sorted order. Earlier elements are no greater and later ones no smaller; neither side is guaranteed sorted. Expected stdout (not executed): 2 5 2 Common mistake: Assuming the entire sequence has been sorted.

Formal Syntax & Structure

rust syntaxrust
slice.select_nth_unstable(index)

Working Example

Example Snippetrust
fn main() {    let mut scores = [9, 1, 5, 3, 7];    let (lower, median, upper) = scores.select_nth_unstable(2);    println!("{} {} {}", lower.len(), *median, upper.len());}
Rust Reference