Skip to content

Commit c527f83

Browse files
authored
Update 4.shellSort.md
1 parent bf9e301 commit c527f83

File tree

1 file changed

+24
-0
lines changed

1 file changed

+24
-0
lines changed

4.shellSort.md

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,30 @@ def shellSort(arr):
6363
}
6464
```
6565

66+
不太明白作者一下代码的含义,
67+
```python
68+
while(gap < len(arr)/3):
69+
gap = gap*3+1
70+
```
71+
按照大部分博客说每次都除以2,以下代码也是可行的
72+
```python
73+
def shellSort(arr):
74+
import math
75+
gap=len(arr)/2
76+
77+
while gap > 0:
78+
for i in range(gap,len(arr)):
79+
temp = arr[i]
80+
j = i-gap
81+
while j >=0 and arr[j] > temp:
82+
arr[j+gap]=arr[j]
83+
j-=gap
84+
arr[j+gap] = temp
85+
gap = gap/2
86+
return arr
87+
88+
```
89+
6690
## 4. Go 代码实现
6791

6892
```go

0 commit comments

Comments
 (0)