Created
June 19, 2018 08:34
-
-
Save xuhang57/3f7e05eb3314f0da405bc25b4d54c34c to your computer and use it in GitHub Desktop.
Quick Sort (v1)
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 quick_sort(arr): | |
smaller, equal, greater = [], [], [] | |
if len(arr) > 1: | |
pivot = arr[0] | |
for x in arr: | |
if x < pivot: | |
smaller.append(x) | |
elif x == pivot: | |
equal.append(x) | |
else: | |
greater.append(x) | |
return quick_sort(smaller) + equal + quick_sort(greater) | |
else: | |
return arr | |
quick_sort([12,4,5,6,7,3,1,15]) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment