Skip to content

Instantly share code, notes, and snippets.

@xuhang57
Created June 19, 2018 08:34
Show Gist options
  • Save xuhang57/3f7e05eb3314f0da405bc25b4d54c34c to your computer and use it in GitHub Desktop.
Save xuhang57/3f7e05eb3314f0da405bc25b4d54c34c to your computer and use it in GitHub Desktop.
Quick Sort (v1)
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