2
\$\begingroup\$

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.

\$\endgroup\$
4
  • 1
    \$\begingroup\$ I thought it was more suitable here, since I was asking for a code review ;-) But okay. \$\endgroup\$
    – revliscano
    Jun 22, 2020 at 22:07
  • 1
    \$\begingroup\$ I have edited the post title and body. Could you please take a look at my post now? Thanks for your time. \$\endgroup\$
    – revliscano
    Jun 22, 2020 at 22:16
  • 1
    \$\begingroup\$ You tested this and it throws a recursion error. This means it's not ready for review. Please take a look at the help center and feel free to come back once it works. \$\endgroup\$
    – Mast
    Jun 23, 2020 at 5:34
  • 1
    \$\begingroup\$ Like every straightforward recursive implementation, yours needs recursion depth of n for an n element ordered input. \$\endgroup\$
    – greybeard
    Jun 23, 2020 at 7:13

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Browse other questions tagged or ask your own question.