We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
There was an error while loading. Please reload this page.
1 parent 9d302a2 commit d41475aCopy full SHA for d41475a
4.shellSort.md
@@ -40,4 +40,25 @@ function shellSort(arr) {
40
}
41
return arr;
42
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