[][src]Function sorting_rs::comb_sort::comb_sort

pub fn comb_sort<T: PartialOrd>(input: &mut [T])

Sorts a slice in-place using Comb sort. All kinds of slices can be sorted as long as they implement PartialOrd.

Comb sort is a simple algorithms that improves on bubble sort. It does so by eliminating small values at the end of the list quickly, since these slow down bubble sort. This is solved by comparing elements at the beginning of the list to the end with a so-called gap. As the algorithm the gap size shrinks until it is finally 1, where it is the same as bubble sort.

Examples

let mut vec = vec![9, 7, 8, 5, 1];
sorting_rs::comb_sort(&mut vec);
assert_eq!(vec, &[1, 5, 7, 8, 9]);
let mut strings = vec!["rustc", "cargo", "rustup"];
sorting_rs::comb_sort(&mut strings);
assert_eq!(strings, &["cargo", "rustc", "rustup"]);