Created
June 25, 2016 19:10
-
-
Save KoderDojo/995ecbdd3f7ba41092b209a43f8d6c57 to your computer and use it in GitHub Desktop.
Insertion Sort Using Python
This file contains hidden or 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
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