Created
September 5, 2020 00:17
-
-
Save aj07mm/3dedb77b11357b656c24d46b5ded353c to your computer and use it in GitHub Desktop.
qsort.py
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
# 3 = 2^2 | |
# x = 2 | |
def qsort(arr): | |
print(arr) | |
if len(arr) == 0: | |
return arr | |
pivot = arr[0] | |
sup_arr = [] | |
inf_arr = [] | |
arr.remove(pivot) | |
for n in arr: | |
print('iter') | |
if n > pivot: | |
sup_arr.append(n) | |
else: | |
inf_arr.append(n) | |
return qsort(inf_arr) + [pivot] + qsort(sup_arr) | |
#assert qsort([1]) == [1] | |
#assert qsort([2, 1]) == [1, 2] | |
#assert qsort([3, 2, 1]) == [1, 2, 3] | |
qsort([1, 2, 3]) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment