Skip to content

Instantly share code, notes, and snippets.

@AaronFlower
Created October 27, 2017 02:25
Show Gist options
  • Save AaronFlower/de3e307c4cbd6fd663d8c16c958947fa to your computer and use it in GitHub Desktop.
Save AaronFlower/de3e307c4cbd6fd663d8c16c958947fa to your computer and use it in GitHub Desktop.
insertion-sort python.
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