Quick actions

cmd+k|ctrl+k

Navigation

Languages

Insertion

Snippet info

Language

Rust

Visibility

public

Author

alexis-enrique-martine-maganda

Created

2020-10-20T23:57:37Z

Updated

2020-10-20T23:57:37Z

pub fn insertion_sort<T: Ord>(arr: &mut [T]) {
    for i in 1..arr.len() {
        let mut j = i;
        while j > 0 && arr[j] < arr[j - 1] {
            arr.swap(j, j - 1);
            j = j - 1;
        }
    }
}
fn main() {
    let mut strings = ["Mamá", "Familia", "Casa", "Carro", "Perro"];
    println!("Antes: {:?}", strings);
    insertion_sort(&mut strings);
    println!("Despues:  {:?}\n", strings);
}
INFO