Created
September 5, 2014 09:24
-
-
Save easonhan007/d95c11570b3f5b370000 to your computer and use it in GitHub Desktop.
how to implment insert sort using python
This file contains 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
# 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