Quick actions

cmd+k|ctrl+k

Navigation

Languages

Bubbles

Snippet info

Language

Rust

Visibility

public

Author

alexis-enrique-martine-maganda

Created

2020-10-20T17:00:43Z

Updated

2020-10-21T01:14:17Z

fn main() {
    println!("Sort Bubbles en Números:");
    let mut numbers = [4, 65, 2, -31, 0, 99, 2, 83, 782, 1];
    println!("Antes: {:?}", numbers);
    bubble_sort(&mut numbers);
    println!("Despues:  {:?}\n", numbers);
}

pub fn bubble_sort<T: Ord>(arr: &mut [T]) {
    for i in 0..arr.len() {
        for j in 0..arr.len() - 1 - i {
            if arr[j] > arr[j + 1] {
                arr.swap(j, j + 1);
            }
        }
    }
}
INFO