Skip to content

Instantly share code, notes, and snippets.

@globby
Created March 3, 2014 23:41
Show Gist options
  • Save globby/9337071 to your computer and use it in GitHub Desktop.
Save globby/9337071 to your computer and use it in GitHub Desktop.
The Insertion Sort algorithm
def insertion(a):
if len(a) < 2: return
for i in range(len(a)):
k = i
while k > 1 and a[k] < a[k-1]:
a[k], a[k-1] = a[k-1], a[k]
k -= 1
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment