cargo fmt rust code (#1131)

* cargo fmt code

* Add empty line to seperate unrelated comments

* Fix review

* Update bubble_sort.rs

* Update merge_sort.rs

---------

Co-authored-by: Yudong Jin <krahets@163.com>
This commit is contained in:
rongyi
2024-03-16 02:13:41 +08:00
committed by GitHub
parent 54ceef3443
commit 7b1094318b
70 changed files with 1021 additions and 836 deletions

View File

@ -49,9 +49,10 @@ fn quadratic(n: i32) -> i32 {
/* 平方阶(冒泡排序) */
fn bubble_sort(nums: &mut [i32]) -> i32 {
let mut count = 0; // 计数器
// 外循环:未排序区间为 [0, i]
for i in (1..nums.len()).rev() {
// 内循环:将未排序区间 [0, i] 中的最大元素交换至该区间的最右端
// 内循环:将未排序区间 [0, i] 中的最大元素交换至该区间的最右端
for j in 0..i {
if nums[j] > nums[j + 1] {
// 交换 nums[j] 与 nums[j + 1]
@ -112,10 +113,10 @@ fn linear_log_recur(n: f32) -> i32 {
return 1;
}
let mut count = linear_log_recur(n / 2.0) + linear_log_recur(n / 2.0);
for _ in 0 ..n as i32 {
for _ in 0..n as i32 {
count += 1;
}
return count
return count;
}
/* 阶乘阶(递归实现) */