|
@ -16,17 +16,12 @@ |
|
|
|
|
|
|
|
|
* **代码** |
|
|
* **代码** |
|
|
|
|
|
|
|
|
```java |
|
|
|
|
|
|
|
|
|
|
|
``` |
|
|
|
|
|
|
|
|
|
|
|
```go |
|
|
```go |
|
|
... |
|
|
func main(){ |
|
|
for d := len(a); d >= 1; d = d/2 { |
|
|
for d := len(a); d >= 1; d = d/2 { |
|
|
Shell(a, d) |
|
|
Shell(a, d) |
|
|
} |
|
|
} |
|
|
... |
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/** |
|
|
/** |
|
@ -42,13 +37,9 @@ func Shell(s []int, get int) { |
|
|
for i := get; i < n; i++ { |
|
|
for i := get; i < n; i++ { |
|
|
for j := i; j > 0 && s[j] < s[j - get]; j = j - get { |
|
|
for j := i; j > 0 && s[j] < s[j - get]; j = j - get { |
|
|
// 选择第j张比较第j - get张小,则循环交换较大的值 |
|
|
// 选择第j张比较第j - get张小,则循环交换较大的值 |
|
|
swap(s, j, j - get) |
|
|
s[j], s[j - get] = s[j - get], s[j] |
|
|
} |
|
|
} |
|
|
} |
|
|
} |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
func swap(slice []int, i int, j int) { |
|
|
|
|
|
slice[i], slice[j] = slice[j], slice[i] |
|
|
|
|
|
} |
|
|
|
|
|
``` |
|
|
``` |
|
|
|
|
|
|
|
|