希尔排序

参考:https://baike.baidu.com/item/%E5%B8%8C%E5%B0%94%E6%8E%92%E5%BA%8F/3229428?fr=aladdin

1
2
3
4
5
6
7
8
9
10
11
12
13
14

//希尔排序
func shellSort(arr []int) {
length := len(arr)
for step := length / 2; step > 0; step /= 2 {
for i := step; i < length; i += step {
for j := i; j >= 0; j -= step {
if j > 0 && arr[j] < arr[j-step] {
arr[j-step], arr[j] = arr[j], arr[j-step]
}
}
}
}
}