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\$ Commented 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\$ Commented 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\$ Commented 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\$ Commented Jun 23, 2020 at 7:13

0

You must log in to answer this question.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.