[−][src]Function sorting_rs::quick_sort::quick_sort
pub fn quick_sort<T: PartialOrd>(input: &mut [T])
Sorts a slice in-place using
Quick sort.
All kinds of slices can be sorted as long as they implement
PartialOrd
.
Quicksort can be compared to merge sort as it also is a divide-and-conquer algorithm. However, quicksort does all the heavy work before the recursive calls, so it could also be called a conquer-and-divide algorithm. This implementation uses the Lomuto partition scheme.
Examples
let mut vec = vec![0, -1, -2, -3,]; sorting_rs::quick_sort(&mut vec); assert_eq!(vec, &[-3, -2, -1, 0]);
let mut strings = vec!["rustc", "cargo", "rustup"]; sorting_rs::quick_sort(&mut strings); assert_eq!(strings, &["cargo", "rustc", "rustup"]);