Last active
September 24, 2018 09:13
-
-
Save SuvroBaner/8304a53d9395335d09dbd425b5a4c72a 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
alist = ['h', 'e', 'a', 'd'] | |
def insertionSort(alist): | |
for i in range(1, len(alist)): # it starts from position 1 , i.e. "e" and goes till end od the string "d" | |
j = i | |
current_value = alist[i] | |
print("Iteration: ", i) | |
while (j > 0 and current_value < alist[j-1]): | |
alist[j] = alist[j-1] | |
j = j - 1 | |
print(alist) | |
alist[j] = current_value | |
print(alist) | |
print('\n') | |
insertionSort(alist) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment