[][src]Function sorting_rs::gnome_sort::gnome_sort

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

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

Gnome sort is also known as stupid sort, because it is very easy to understand and not very efficient. It is based on how a gnome would sort flower pots.

Upgraded version of algorithm just remember last sort position, so it doesn't try to sort already sorted data.

Examples

let mut vec = vec![5,3,2,4];
sorting_rs::gnome_sort(&mut vec);
assert_eq!(vec, &[2,3,4,5]);
let mut strings = vec!["rustc", "cargo", "rustup"];
sorting_rs::gnome_sort(&mut strings);
assert_eq!(strings, &["cargo", "rustc", "rustup"]);
let mut vec = vec![5,3,2,4];
sorting_rs::gnome_up_sort(&mut vec);
assert_eq!(vec, &[2,3,4,5]);
let mut strings = vec!["rustc", "cargo", "rustup"];
sorting_rs::gnome_up_sort(&mut strings);
assert_eq!(strings, &["cargo", "rustc", "rustup"]);