[−][src]Function sorting_rs::pancake_sort::pancake_sort
pub fn pancake_sort<T: PartialOrd + Copy>(input: &mut [T])
Sorts a slice in-place using
Pancake sort.
All kinds of slices can be sorted as long as they implement
PartialOrd
.
This algorithm aims to minimize number of comparisons, though amount of data swaps is pretty high, which doesn't make it very effective in practical use
Examples
let mut vec = vec![56, 32, 78, 16]; sorting_rs::pancake_sort(&mut vec); assert_eq!(vec, &[16, 32, 56, 78]);
let mut strings = vec!["rustc", "cargo", "rustup"]; sorting_rs::pancake_sort(&mut strings); assert_eq!(strings, &["cargo", "rustc", "rustup"]);