Created
October 27, 2017 02:25
-
-
Save AaronFlower/de3e307c4cbd6fd663d8c16c958947fa to your computer and use it in GitHub Desktop.
insertion-sort 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
def insertion_sort(data): | |
length = len(data) | |
for i in range(1, length): | |
j = i | |
while j > 0 and data[j] < data[j-1]: | |
tmp = data[j-1] | |
data[j - 1] = data[j] | |
data[j] = tmp | |
j -= 1 | |
data = [ 2, 9, 1, 8, 3, 5] | |
insertion_sort(data) | |
print(data) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment