Skip to content

Instantly share code, notes, and snippets.

@rcanepa
Last active August 29, 2015 14:15
Show Gist options
  • Save rcanepa/236e1af93969e665268f to your computer and use it in GitHub Desktop.
Save rcanepa/236e1af93969e665268f to your computer and use it in GitHub Desktop.
Python Insertion Sort
def insertion_sort(arr):
for idx, number in enumerate(arr):
current = idx
previous = idx - 1
if idx > 0:
while arr[current] < arr[previous] and (previous >= 0):
temp = arr[current]
arr[current] = arr[previous]
arr[previous] = temp
current = previous
previous -= 1
return arr
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment