Skip to content

Instantly share code, notes, and snippets.

@samrat
Created July 3, 2011 08:16
Show Gist options
  • Save samrat/1062064 to your computer and use it in GitHub Desktop.
Save samrat/1062064 to your computer and use it in GitHub Desktop.
Insertion sort implementation in Python(probably not very efficient)
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