Skip to content

Instantly share code, notes, and snippets.

@easonhan007
Created September 5, 2014 09:24
Show Gist options
  • Save easonhan007/d95c11570b3f5b370000 to your computer and use it in GitHub Desktop.
Save easonhan007/d95c11570b3f5b370000 to your computer and use it in GitHub Desktop.
how to implment insert sort using python
# insert sort using python
def insert_sort(the_list):
for i in range(1,len(the_list)):
print 'key is %d' %(key)
current = i - 1
while the_list[current] > key and current >= 0:
the_list[current + 1] = the_list[current]
current = current - 1
the_list[current + 1] = key
return the_list
array = [9, 8, 7, 5, 45, 1234, 32]
print insert_sort(array)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment