Last active
August 29, 2015 14:11
-
-
Save kayluhb/fa335378b2b8a5333da0 to your computer and use it in GitHub Desktop.
Quick Sort python
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(lst): | |
if len(lst) <= 1: | |
return lst | |
low, middle, high = [], [], [] | |
pivot = lst[0] | |
for num in lst: | |
if num < pivot: | |
low.append(num) | |
elif num > pivot: | |
high.append(num) | |
else: | |
middle.append(num) | |
low = quick_sort(low) | |
high = quick_sort(high) | |
return low + middle + high | |
print(quick_sort([0, 30, -40, 300, 10, 4, 34, -6])) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment