Skip to content

Instantly share code, notes, and snippets.

@ls0f
Created September 11, 2015 16:14
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 ls0f/c1b1e05d7abac26b6370 to your computer and use it in GitHub Desktop.
Save ls0f/c1b1e05d7abac26b6370 to your computer and use it in GitHub Desktop.
#coding:utf-8
def insert_sort(array):
if len(array) <= 1:
return
for i in range(1, len(array)):
j = i
while j > 0:
if array[j] >= array[j-1]:
break
array[j], array[j-1] = array[j-1], array[j]
j -= 1
if __name__ == "__main__":
a1 = [3,1,0,1,5,98,78,11]
insert_sort(a1)
print a1
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment