Skip to content

Instantly share code, notes, and snippets.

@horiajurcut
Created August 12, 2013 21:54
Show Gist options
  • Save horiajurcut/6215644 to your computer and use it in GitHub Desktop.
Save horiajurcut/6215644 to your computer and use it in GitHub Desktop.
def insertion_sort(a = []):
length = len(a)
j = 1
while j < length:
key = a[j]
i = j - 1
while i >= 0 and a[i] > key:
a[i + 1] = a[i]
i = i - 1
a[i + 1] = key
j = j + 1
return a
print insertion_sort([5, 3, 10, 2, 0, 1, 8, 9])
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment