Insertion sort using go

pull/92/head
machangxin 2 years ago
parent 51a6f374a7
commit e2ae907cd1

@ -1,8 +1,7 @@
/*
File: insertion_sort.go
Created Time: 2022-12-12
Author: msk397 (machangxinq@gmail.com)
*/
//File: insertion_sort.go
//Created Time: 2022-12-12
//Author: msk397 (machangxinq@gmail.com)
package insertion_sort
func insertionSort(nums []int) {

@ -1,8 +1,7 @@
/*
File: insertion_sort_test.go
Created Time: 2022-12-12
Author: msk397 (machangxinq@gmail.com)
*/
//File: insertion_sort_test.go
//Created Time: 2022-12-12
//Author: msk397 (machangxinq@gmail.com)
package insertion_sort
import (

@ -87,13 +87,12 @@ comments: true
j := i - 1
// 内循环:将 base 插入到左边的正确位置
for j >= 0 && nums[j] > base {
nums[j+1] = nums[j] // 1. 将 nums[j] 向右移动一位
nums[j+1] = nums[j] // 1. 将 nums[j] 向右移动一位
j--
}
nums[j+1] = base // 2. 将 base 赋值到正确位置
nums[j+1] = base // 2. 将 base 赋值到正确位置
}
}
}
```
=== "JavaScript"

Loading…
Cancel
Save