Skip to content

Instantly share code, notes, and snippets.

@anil477
Created January 27, 2017 19:00
Show Gist options
  • Save anil477/3a859b91ca17f13a38d21e66caa904d7 to your computer and use it in GitHub Desktop.
Save anil477/3a859b91ca17f13a38d21e66caa904d7 to your computer and use it in GitHub Desktop.
Insertion Sort
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