Skip to content

Instantly share code, notes, and snippets.

@phalt
Created October 29, 2014 22:41
Show Gist options
  • Select an option

  • Save phalt/1d4cd99108ad455f873c to your computer and use it in GitHub Desktop.

Select an option

Save phalt/1d4cd99108ad455f873c to your computer and use it in GitHub Desktop.
Linear / insertion sort in Python
haystack = [5,3,2,4,1]
for i in range(1, len(haystack)):
x = haystack[i]
c = i
while c > 0 and haystack[c-1] > x:
haystack[c] = haystack[c-1]
c = c - 1
haystack[c] = x
print haystack
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment