Skip to content

Instantly share code, notes, and snippets.

@rochacbruno
Forked from fmasanori/quicksort.py
Created July 13, 2014 17:06
Show Gist options
  • Save rochacbruno/50bd58495a88192549a6 to your computer and use it in GitHub Desktop.
Save rochacbruno/50bd58495a88192549a6 to your computer and use it in GitHub Desktop.
def quicksort(v):
if len(v) <= 1:
return v
pivot = v[0]
equals = [x for x in v if x == pivot]
smaller = [x for x in v if x < pivot]
higher = [x for x in v if x > pivot]
return quicksort(smaller) + equals + quicksort(higher)
print (quicksort([5, 7, 9, 3, 4, 0, 2, 1, 6, 8]))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment