Skip to content

Instantly share code, notes, and snippets.

@joubertnel
Created November 5, 2010 21:23
Show Gist options
  • Save joubertnel/664894 to your computer and use it in GitHub Desktop.
Save joubertnel/664894 to your computer and use it in GitHub Desktop.
Insertion sort in Python
def insertion_sort(keys):
index = 1
while index < len(keys):
key = keys[index]
comp_index = index - 1
while comp_index >= 0 and key < keys[comp_index]:
keys[comp_index], keys[comp_index+1] = keys[comp_index+1], keys[comp_index]
comp_index -= 1
index += 1
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment