MCPcopy Create free account
hub / github.com/QMHTMY/RustBook / bubble_sort1

Function bubble_sort1

publication/code/chapter07/bubble_sort.rs:3–16  ·  view source on GitHub ↗
(nums: &mut [i32])

Source from the content-addressed store, hash-verified

1// bubble_sort.rs
2
3fn bubble_sort1(nums: &mut [i32]) {
4 // 数据量小于 2,直接返回
5 if nums.len() < 2 {
6 return;
7 }
8
9 for i in 1..nums.len() {
10 for j in 0..nums.len() - i {
11 if nums[j] > nums[j+1] {
12 nums.swap(j, j+1);
13 }
14 }
15 }
16}
17
18fn bubble_sort2(nums: &mut [i32]) {
19 let mut len = nums.len() - 1;

Callers 1

mainFunction · 0.70

Calls 1

lenMethod · 0.45

Tested by

no test coverage detected