Skip to content

Commit ddae517

Browse files
committed
fix: update shell sort code and fix some describe
1 parent 94dc08a commit ddae517

File tree

2 files changed

+2
-2
lines changed

2 files changed

+2
-2
lines changed

algorithm/sort/shell_sort.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -107,7 +107,7 @@ func ShellSort(list []int) {
107107
if deal < list[j] {
108108
// 一直往左边找,比待排序大的数都往后挪,腾空位给待排序插入
109109
for ; j >= 0 && deal < list[j]; j -= step {
110-
list[j+1] = list[j] // 某数后移,给待排序留空位
110+
list[j+step] = list[j] // 某数后移,给待排序留空位(注意移动是以step为步长)
111111
}
112112
list[j+step] = deal // 结束了,待排序的数插入空位
113113
}

code/sort/shell.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ func ShellSort(list []int) {
2121
if deal < list[j] {
2222
// 一直往左边找,比待排序大的数都往后挪,腾空位给待排序插入
2323
for ; j >= 0 && deal < list[j]; j -= step {
24-
list[j+1] = list[j] // 某数后移,给待排序留空位
24+
list[j+step] = list[j] // 某数后移,给待排序留空位(注意移动是以step为步长)
2525
}
2626
list[j+step] = deal // 结束了,待排序的数插入空位
2727
}

0 commit comments

Comments
 (0)