rusty_sorts/
lib.rs

1//! A crate that contains some basic sorting algorithms.
2
3/// A function for sorting an array of integers with insertion sort.
4pub fn insertion_sort<T>(mut to_sort: Vec<T>) -> Vec<T>
5where
6    T: PartialOrd + Copy,
7{
8    for i in 1..to_sort.len() {
9        let mut j = i;
10        while j > 0 && to_sort[j - 1] > to_sort[j] {
11            to_sort.swap(j - 1, j);
12            j -= 1;
13        }
14    }
15    to_sort
16}
17
18mod test;