Skip to content

Instantly share code, notes, and snippets.

@KoderDojo
Created June 25, 2016 19:10
Show Gist options
  • Save KoderDojo/995ecbdd3f7ba41092b209a43f8d6c57 to your computer and use it in GitHub Desktop.
Save KoderDojo/995ecbdd3f7ba41092b209a43f8d6c57 to your computer and use it in GitHub Desktop.
Insertion Sort Using Python
import random
def InsertionSort(lst):
print 'List {}'.format(lst)
length = len(lst)
for i in range(1, length):
value = lst[i]
j = i - 1
while j > -1 and value < lst[j]:
lst[j + 1] = lst[j]
j -= 1
lst[j + 1] = value
print 'Pass {:2} {}'.format(i, lst)
numbers = range(20)
random.shuffle(numbers)
InsertionSort(numbers)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment