使用rust写的冒泡排序
fn bubble_sort(arr: &mut [u32]) {
let len = arr.len();
for i in 0.. len {
for j in 0.. len - i - 1 {
if arr[j] > arr[j + 1] {
arr.swap(j, j+ 1);
}
}
}
}
fn main() {
let mut arr = [5, 2, 9, 1, 3];
println!("Before sorting: {:?}", arr);
bubble_sort(&mut arr);
println!("After sorting: {:?}", arr);
}