Skip to content

Commit 01c6778

Browse files
authored
Bug fixes and improvements (krahets#1133)
* Bug fixes * Update the figure of the JD link * Unify the code comments of insertion_sort
1 parent eadf4c8 commit 01c6778

File tree

14 files changed

+23
-23
lines changed

14 files changed

+23
-23
lines changed

codes/c/chapter_sorting/insertion_sort.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,10 +8,10 @@
88

99
/* 插入排序 */
1010
void insertionSort(int nums[], int size) {
11-
// 外循环:已排序元素数量为 1, 2, ..., n
11+
// 外循环:已排序区间为 [0, i-1]
1212
for (int i = 1; i < size; i++) {
1313
int base = nums[i], j = i - 1;
14-
// 内循环:将 base 插入到已排序部分的正确位置
14+
// 内循环:将 base 插入到已排序区间 [0, i-1] 中的正确位置
1515
while (j >= 0 && nums[j] > base) {
1616
// 将 nums[j] 向右移动一位
1717
nums[j + 1] = nums[j];

codes/cpp/chapter_sorting/insertion_sort.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,10 +8,10 @@
88

99
/* 插入排序 */
1010
void insertionSort(vector<int> &nums) {
11-
// 外循环:已排序元素数量为 1, 2, ..., n
11+
// 外循环:已排序区间为 [0, i-1]
1212
for (int i = 1; i < nums.size(); i++) {
1313
int base = nums[i], j = i - 1;
14-
// 内循环:将 base 插入到已排序部分的正确位置
14+
// 内循环:将 base 插入到已排序区间 [0, i-1] 中的正确位置
1515
while (j >= 0 && nums[j] > base) {
1616
nums[j + 1] = nums[j]; // 将 nums[j] 向右移动一位
1717
j--;

codes/csharp/chapter_sorting/insertion_sort.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,10 +9,10 @@ namespace hello_algo.chapter_sorting;
99
public class insertion_sort {
1010
/* 插入排序 */
1111
void InsertionSort(int[] nums) {
12-
// 外循环:已排序元素数量为 1, 2, ..., n
12+
// 外循环:已排序区间为 [0, i-1]
1313
for (int i = 1; i < nums.Length; i++) {
1414
int bas = nums[i], j = i - 1;
15-
// 内循环:将 base 插入到已排序部分的正确位置
15+
// 内循环:将 base 插入到已排序区间 [0, i-1] 中的正确位置
1616
while (j >= 0 && nums[j] > bas) {
1717
nums[j + 1] = nums[j]; // 将 nums[j] 向右移动一位
1818
j--;

codes/dart/chapter_sorting/insertion_sort.dart

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,10 +6,10 @@
66

77
/* 插入排序 */
88
void insertionSort(List<int> nums) {
9-
// 外循环:已排序元素数量为 1, 2, ..., n
9+
// 外循环:已排序区间为 [0, i-1]
1010
for (int i = 1; i < nums.length; i++) {
1111
int base = nums[i], j = i - 1;
12-
// 内循环:将 base 插入到已排序部分的正确位置
12+
// 内循环:将 base 插入到已排序区间 [0, i-1] 中的正确位置
1313
while (j >= 0 && nums[j] > base) {
1414
nums[j + 1] = nums[j]; // 将 nums[j] 向右移动一位
1515
j--;

codes/go/chapter_sorting/insertion_sort.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ func insertionSort(nums []int) {
1010
for i := 1; i < len(nums); i++ {
1111
base := nums[i]
1212
j := i - 1
13-
// 内循环:将 base 插入到已排序部分的正确位置
13+
// 内循环:将 base 插入到已排序区间 [0, i-1] 中的正确位置
1414
for j >= 0 && nums[j] > base {
1515
nums[j+1] = nums[j] // 将 nums[j] 向右移动一位
1616
j--

codes/java/chapter_sorting/insertion_sort.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,10 +11,10 @@
1111
public class insertion_sort {
1212
/* 插入排序 */
1313
static void insertionSort(int[] nums) {
14-
// 外循环:已排序元素数量为 1, 2, ..., n
14+
// 外循环:已排序区间为 [0, i-1]
1515
for (int i = 1; i < nums.length; i++) {
1616
int base = nums[i], j = i - 1;
17-
// 内循环:将 base 插入到已排序部分的正确位置
17+
// 内循环:将 base 插入到已排序区间 [0, i-1] 中的正确位置
1818
while (j >= 0 && nums[j] > base) {
1919
nums[j + 1] = nums[j]; // 将 nums[j] 向右移动一位
2020
j--;

codes/javascript/chapter_sorting/insertion_sort.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,11 +6,11 @@
66

77
/* 插入排序 */
88
function insertionSort(nums) {
9-
// 外循环:已排序元素数量为 1, 2, ..., n
9+
// 外循环:已排序区间为 [0, i-1]
1010
for (let i = 1; i < nums.length; i++) {
1111
let base = nums[i],
1212
j = i - 1;
13-
// 内循环:将 base 插入到已排序部分的正确位置
13+
// 内循环:将 base 插入到已排序区间 [0, i-1] 中的正确位置
1414
while (j >= 0 && nums[j] > base) {
1515
nums[j + 1] = nums[j]; // 将 nums[j] 向右移动一位
1616
j--;

codes/rust/chapter_sorting/insertion_sort.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,10 +8,10 @@ include!("../include/include.rs");
88

99
/* 插入排序 */
1010
fn insertion_sort(nums: &mut [i32]) {
11-
// 外循环:已排序元素数量为 1, 2, ..., n
11+
// 外循环:已排序区间为 [0, i-1]
1212
for i in 1..nums.len() {
1313
let (base, mut j) = (nums[i], (i - 1) as i32);
14-
// 内循环:将 base 插入到已排序部分的正确位置
14+
// 内循环:将 base 插入到已排序区间 [0, i-1] 中的正确位置
1515
while j >= 0 && nums[j as usize] > base {
1616
nums[(j + 1) as usize] = nums[j as usize]; // 将 nums[j] 向右移动一位
1717
j -= 1;

codes/swift/chapter_sorting/insertion_sort.swift

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,11 +6,11 @@
66

77
/* 插入排序 */
88
func insertionSort(nums: inout [Int]) {
9-
// 外循环:已排序元素数量为 1, 2, ..., n
9+
// 外循环:已排序区间为 [0, i-1]
1010
for i in stride(from: 1, to: nums.count, by: 1) {
1111
let base = nums[i]
1212
var j = i - 1
13-
// 内循环:将 base 插入到已排序部分的正确位置
13+
// 内循环:将 base 插入到已排序区间 [0, i-1] 中的正确位置
1414
while j >= 0, nums[j] > base {
1515
nums[j + 1] = nums[j] // 将 nums[j] 向右移动一位
1616
j -= 1

codes/typescript/chapter_sorting/insertion_sort.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,11 +6,11 @@
66

77
/* 插入排序 */
88
function insertionSort(nums: number[]): void {
9-
// 外循环:已排序元素数量为 1, 2, ..., n
9+
// 外循环:已排序区间为 [0, i-1]
1010
for (let i = 1; i < nums.length; i++) {
1111
const base = nums[i];
1212
let j = i - 1;
13-
// 内循环:将 base 插入到已排序部分的正确位置
13+
// 内循环:将 base 插入到已排序区间 [0, i-1] 中的正确位置
1414
while (j >= 0 && nums[j] > base) {
1515
nums[j + 1] = nums[j]; // 将 nums[j] 向右移动一位
1616
j--;

0 commit comments

Comments
 (0)