golang 希尔排序算法
package main
import "fmt"
func main() {
arr := []int{10, 8, 2, 4, 3, 5, 1, 6, 7, 9}
fmt.Println(arr)
shellSort(arr)
fmt.Println(arr)
}
func shellSort(arr []int) {
llen := len(arr)
for w := llen / 2; w > 0; w = w / 2 {
for i := w; i < llen; i++ {
tmp := arr[i]
var j int
for j = i - w; j >= 0; j -= w {
if tmp < arr[j] {
arr[j+w] = arr[j]
} else {
break
}
}
arr[j+w] = tmp
}
}
}