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