Skip to content

Instantly share code, notes, and snippets.

@bag-man
Last active August 29, 2015 14:20
Show Gist options
  • Save bag-man/5b7bae0832e6d8fffa4a to your computer and use it in GitHub Desktop.
Save bag-man/5b7bae0832e6d8fffa4a to your computer and use it in GitHub Desktop.
Quicksort
def quicksort(arr):
if not arr:
return []
pivot = arr[-1]
less = [x for x in arr[:-1] if x <= pivot]
more = [x for x in arr[:-1] if x > pivot]
lesser = quicksort(less)
greater = quicksort(more)
return lesser + [pivot] + greater
data = [3, 5, 2, 1, 7, 6, 9, 0, 8, 4]
print data
print quicksort(data)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment