
pub fn bubble_sort<T:PartialOrd>(input: &mut [T]) {
    for i in 0..input.len() {
        let mut is_sorted = true;
        for j in 0..(input.len() - 1) - i {
            if input[j] > input[j + 1] {
                input.swap(j, j +1);
                is_sorted = false;
            }
        }
        if is_sorted {
            return
        }
    }
}

#[cfg(test)]
mod tests {
    use super::*;

    #[test]
    fn test_bubble_sort() {
        let mut v = vec![5, 4, 9, 12, 16, 100, 2];
        bubble_sort(&mut v);
        assert_eq!(v, vec![2, 4, 5, 9, 12, 16, 100]);
    }
}
