Created
January 27, 2017 19:00
-
-
Save anil477/3a859b91ca17f13a38d21e66caa904d7 to your computer and use it in GitHub Desktop.
Insertion Sort
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
def insertionSort(alist): | |
for index in range(1, len(alist)): | |
currentvalue = alist[index] | |
position = index | |
while position > 0 and alist[position - 1] > currentvalue: | |
alist[position] = alist[position - 1] | |
position = position - 1 | |
alist[position] = currentvalue | |
alist = [54, 56, 17, 77, 31, 44, 55, 20] | |
insertionSort(alist) | |
print(alist) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment