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

Function bubble_sort2

code/chapter06/bubble_sort.rs:18–28  ·  view source on GitHub ↗
(nums: &mut [i32])

Source from the content-addressed store, hash-verified

16}
17
18fn bubble_sort2(nums: &mut [i32]) {
19 let mut len = nums.len() - 1;
20 while len > 0 {
21 for i in 0..len {
22 if nums[i] > nums[i+1] {
23 nums.swap(i, i+1);
24 }
25 }
26 len -= 1;
27 }
28}
29
30fn bubble_sort3(nums: &mut [i32]) {
31 let mut compare = true;

Callers

nothing calls this directly

Calls 1

lenMethod · 0.45

Tested by

no test coverage detected