Skip to content

Instantly share code, notes, and snippets.

@globby
Created March 3, 2014 23:44
Show Gist options
  • Save globby/9337111 to your computer and use it in GitHub Desktop.
Save globby/9337111 to your computer and use it in GitHub Desktop.
The Quicksort algorithm
def quicksort(a):
if len(a) <= 1: return a
pivot = a.pop(len(a)/2)
less, greater = [], []
for x in a:
if x <= pivot:
less.append(x)
else:
greater.append(x)
return quicksort(less) + [pivot] + quicksort(greater)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment