python - QuickSort - RuntimeError: maximum recursion depth exceeded -


this question has answer here:

i writed simple quicksort, have problems it.

def partition(a, p, r):     x = a[r]     = p     j = r     while true:         while a[i] < x:             i+=1         while x < a[j]:             j-=1         if < j:             a[i], a[j] = a[j], a[i]             += 1             j -= 1         else:             return j  def quicksort(a, p, r):     if p<r:         q = partition(a, p, r)         quicksort(a, p, q-1)         quicksort(a, q+1, r)  def quicksortmainreq(a):     quicksort(a, 0, len(a)-1)     return 

everything fine untill don't have big array. example print quicksortmainreq(range(994)) working. print quicksortmainreq(range(995)) isn't. when set x [(p+r)//2] works, must use right pivot have no idea why. should work all.

don't complicate ;) take little, awesome example quick sort


Comments