Skip to content

Instantly share code, notes, and snippets.

@krrr
Last active March 11, 2016 11:58
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save krrr/8fa97f08457bdb15f087 to your computer and use it in GitHub Desktop.
Save krrr/8fa97f08457bdb15f087 to your computer and use it in GitHub Desktop.
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)
@krrr
Copy link
Author

krrr commented Feb 29, 2016

bug exists for one year

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment