Skip to content

Instantly share code, notes, and snippets.

@EdisonChendi
Created April 14, 2018 13:05
Show Gist options
  • Save EdisonChendi/e5960be0da67f234701f9e303da40456 to your computer and use it in GitHub Desktop.
Save EdisonChendi/e5960be0da67f234701f9e303da40456 to your computer and use it in GitHub Desktop.
insertion sort
#codint:UTF-8
def insertion_sort(l):
if len(l) <= 1:
return l
for i in range(1, len(l)):
key = l[i]
for j in reversed(range(0, i)):
c = l[j]
if c > key:
l[j], l[j+1] = key, l[j] # swap
else:
break
l = [7, 3, 8, 10, 11]
insertion_sort(l)
print(l)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment