Created
July 3, 2011 08:16
-
-
Save samrat/1062064 to your computer and use it in GitHub Desktop.
Insertion sort implementation in Python(probably not very efficient)
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
unsorted_list=[45,99,1,-22,7,3,294,10,36] | |
def insertion_sort(unsorted): | |
for i in range(1,len(unsorted)): | |
for j in range(i): | |
if unsorted[i]<unsorted[j]: | |
unsorted[i], unsorted[j] = unsorted[j], unsorted[i] | |
print unsorted | |
return unsorted | |
print insertion_sort(unsorted_list) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment