Bug fixes and improvements (#1133)

* Bug fixes

* Update the figure of the JD link

* Unify the code comments of insertion_sort
This commit is contained in:
Yudong Jin
2024-03-14 20:01:16 +08:00
committed by GitHub
parent eadf4c86d4
commit 01c67781fa
14 changed files with 23 additions and 23 deletions
+2 -2
View File
@@ -8,10 +8,10 @@ include!("../include/include.rs");
/* 插入排序 */
fn insertion_sort(nums: &mut [i32]) {
// 外循环:已排序元素数量为 1, 2, ..., n
// 外循环:已排序区间为 [0, i-1]
for i in 1..nums.len() {
let (base, mut j) = (nums[i], (i - 1) as i32);
// 内循环:将 base 插入到已排序部分的正确位置
// 内循环:将 base 插入到已排序区间 [0, i-1] 中的正确位置
while j >= 0 && nums[j as usize] > base {
nums[(j + 1) as usize] = nums[j as usize]; // 将 nums[j] 向右移动一位
j -= 1;