Skip to content

Instantly share code, notes, and snippets.

@SuvroBaner
Last active September 24, 2018 09:13
Show Gist options
  • Save SuvroBaner/8304a53d9395335d09dbd425b5a4c72a to your computer and use it in GitHub Desktop.
Save SuvroBaner/8304a53d9395335d09dbd425b5a4c72a to your computer and use it in GitHub Desktop.
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