Rust Bubble Sort

Published 361d ago

 nptester

Bubble sort algorithm in Rust

fn bubble_sort(arr: &mut [i32]) {
    let mut swapped = true;
    while swapped {
        swapped = false;
        for i in 1..arr.len() {
            if arr[i - 1] > arr[i] {
                arr.swap(i - 1, i);
                swapped = true;
            }
        }
    }
}

sortingbubble sortRust
1

Please login or sign up to comment and collaborate