Created
January 18, 2017 23:50
-
-
Save jonathan-kosgei/4e6066773b71c8639378073004b359dc to your computer and use it in GitHub Desktop.
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
>>> 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