We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
There was an error while loading. Please reload this page.
1 parent b79b97e commit 369aaafCopy full SHA for 369aaaf
3.insertionSort.md
@@ -53,10 +53,15 @@ def insertionSort(arr):
53
## 5. Go 代码实现
54
```go
55
func insertionSort(arr []int) []int {
56
- for i := range arr {
+ for i, _ := range arr {
57
+ //前面那个数位。
58
preIndex := i - 1
59
+ // 正在遍历的那个数位。
60
current := arr[i]
61
+ // 假如说 前面的那个数位大于等于0并且,
62
+ // 前面的那个数值是大于正在遍历的那个数值的
63
for preIndex >= 0 && arr[preIndex] > current {
64
+ // 正在正在遍历的那个次数就和它前面的那个交换顺序。并且preindex要减去1
65
arr[preIndex+1] = arr[preIndex]
66
preIndex -= 1
67
}
0 commit comments