Created
September 14, 2018 05:28
-
-
Save Xifeng2009/8b7f51fe9d64bbd30238e3b055ddc545 to your computer and use it in GitHub Desktop.
希尔排序
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def shell(arr): | |
n=len(arr) | |
h=1 | |
while h<n/3: | |
h=3*h+1 | |
while h>=1: | |
for i in range(h,n): | |
j=i | |
while j>=h and arr[j]<arr[j-h]: | |
arr[j], arr[j-h] = arr[j-h], arr[j] | |
j-=h | |
h=h//3 | |
print arr |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment