Quicksort in place Python
<p>I am extremely new to Python and i am trying my hand in Algorithms. I was just trying my hands in the in place sorting of an array using quicksort algo.</p>

<p>Below is my code . When i run this there is an infinite loop as output. Can anyone kindly go through the code and let me know where i am going wrong logically :</p>

<pre><code>def quicksort(arr,start,end):
    if start &lt; end:
        pivot = arr[int(start + (end - start)/2)]
        while end &gt; start:
            while arr[start] &lt; pivot:
                start = start + 1
            while arr[end] &gt; pivot:
                end = end - 1
            if start &lt;= end:
                arr[start],arr[end] = arr[end],arr[start]
                start = start + 1 
                end = end - 1


        quicksort(arr,0,end)
        quicksort(arr,start,len(arr) - 1)
    else:    
        return



arr = list(map(int,input().split(" ")))
quicksort(arr,0,len(arr) - 1)

print ("The final sorted array:",arr)
</code></pre>

<p>Thanks for any help in advance.</p>

<p>Your recursion is wrong. After doing Hoare Partition, you should do :</p>

<ul>
<li>call quicksort from start (of data that being sorted) to index that run from the end, and</li>
<li>call quicksort from end (of data that being sorted) to index that run from the start</li>
</ul>

<p>So you have to create new variables beside the argument to maintain start,end and indices that move toward each other in the partition.</p>

<p>In order to not change a lot of your code, i suggest you to change the argument</p>

<pre><code>def quicksort(arr,left,right):
    start = left
    end = right
</code></pre>

<p>and do this in the recursion</p>

<pre><code>quicksort(arr,left,end)
quicksort(arr,start,right)
</code></pre>

python