I was playing around with sorting methods, brushing up on my algorithms. I have made the following implementation of quicksort:
def quicksort(l):
def inner_qs(list_, start, end):
if end - start > 1:
piv = list_[end - 1]
aux_index = start
for i in range(start, end):
if list_[i] < piv or i == end - 1:
list_[aux_index], list_[i] = list_[i], list_[aux_index]
aux_index += 1
pivot_position = aux_index - 1
# left
inner_qs(list_, start=start, end=pivot_position)
# right
inner_qs(list_, start=pivot_position + 1, end=end)
l = l[:]
inner_qs(l, 0, len(l))
return l
Please, take a look at it.