Last active
August 29, 2015 14:20
-
-
Save bag-man/5b7bae0832e6d8fffa4a to your computer and use it in GitHub Desktop.
Quicksort
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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