Skip to content

Instantly share code, notes, and snippets.

@aj07mm
Created September 5, 2020 00:17
Show Gist options
  • Save aj07mm/3dedb77b11357b656c24d46b5ded353c to your computer and use it in GitHub Desktop.
Save aj07mm/3dedb77b11357b656c24d46b5ded353c to your computer and use it in GitHub Desktop.
qsort.py
# 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