1
2
3
4
5
6
7
8
9
10
11
12
13
|
func shellSort(unsorted [] int , n int ) {
var i, j, gap int
var temp int
for gap = n / 2 ; gap > 0 ; gap / = 2 {
for i = gap; i < n; i + + {
for j = i - gap; j> = 0 && unsorted[j]>unsorted[j + gap]; j - = gap {
temp = unsourted[j]
unsorted[j] = unsorted[j + gap]
unsorted[j + gap] = temp
}
}
}
}
|
本文转自yeleven 51CTO博客,原文链接:http://blog.51cto.com/11317783/1977989