[−][src]Function sorting_rs::insertion_sort::insertion_sort
pub fn insertion_sort<T: PartialOrd>(input: &mut [T])
Sorts a slice in-place using
Insertion sort.
All kinds of slices can be sorted as long as they implement
PartialOrd
.
This sorting algorithm is very efficient when used on small data sets. This is because insertion sort has constant space complexity and works very fast when used on partially sorted data.
Examples
let mut vec = vec![-4, -5, 7, 45, 0]; sorting_rs::insertion_sort(&mut vec); assert_eq!(vec, &[-5, -4, 0, 7, 45]);
let mut strings = vec!["rustc", "cargo", "rustup"]; sorting_rs::shell_sort(&mut strings); assert_eq!(strings, &["cargo", "rustc", "rustup"]);