Skip to content

Instantly share code, notes, and snippets.

@bag-man bag-man/quicksort.py
Last active Aug 29, 2015

Embed
What would you like to do?
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
You can’t perform that action at this time.