Skip to content

Commit d41475a

Browse files
authored
Add Python
1 parent 9d302a2 commit d41475a

File tree

1 file changed

+22
-1
lines changed

1 file changed

+22
-1
lines changed

4.shellSort.md

Lines changed: 22 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,4 +40,25 @@ function shellSort(arr) {
4040
}
4141
return arr;
4242
}
43-
```
43+
```
44+
45+
## 2. Python 代码实现
46+
47+
```python
48+
def shellSort(arr):
49+
import math
50+
gap=1
51+
while(gap < len(arr)/3):
52+
gap = gap*3+1
53+
while gap > 0:
54+
for i in range(gap,len(arr)):
55+
temp = arr[i]
56+
j = i-gap
57+
while j >=0 and arr[j] > temp:
58+
arr[j+gap]=arr[j]
59+
j-=gap
60+
arr[j+gap] = temp
61+
gap = math.floor(gap/3)
62+
return arr
63+
}
64+
```

0 commit comments

Comments
 (0)