Last active
March 11, 2016 11:58
-
-
Save krrr/8fa97f08457bdb15f087 to your computer and use it in GitHub Desktop.
This file contains hidden or 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
gap_seq = [701, 301, 132, 57, 23, 10, 4, 1] | |
def shell_sort(l): | |
for g in gap_seq: | |
insert_sort(l, g) | |
def insert_sort(l, gap=1): | |
# elements whose index < i are sorted | |
for i in range(gap, len(l)): | |
for j in range(i, gap-1, -gap): | |
if l[j] >= l[j-gap]: | |
break | |
l[j], l[j-gap] = l[j-gap], l[j] | |
l = [4, 6, 21, 75, 13, 43, 1, 4] | |
shell_sort(l) | |
print(l) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
bug exists for one year