Skip to content

Instantly share code, notes, and snippets.

@jonathan-kosgei
Created January 18, 2017 23:50
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 jonathan-kosgei/4e6066773b71c8639378073004b359dc to your computer and use it in GitHub Desktop.
Save jonathan-kosgei/4e6066773b71c8639378073004b359dc to your computer and use it in GitHub Desktop.
>>> list2
[5, 5, 5, 5, 5, 4, 4, 2, 1]
>>> def insertion_sort(list2):
... for index in range(1,len(list2)):
... position=index
... currentvalue=list2[index]
... while position>0 and currentvalue<list2[position-1]:
... list2[position]=list2[position-1]
... list2[position-1]=currentvalue
... position-=1
...
>>> insertion_sort(list2)
>>> list2
[1, 2, 4, 4, 5, 5, 5, 5, 5]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment