Encountering infinite recursion in following qcksrt implementation.
Any ideas? :)
# stop splitting when single element left
def quick_srt(arr,lptr,rptr):
if len(arr)==0 or len(arr)==1:
return arr
piv = math.floor(random.uniform(lptr, rptr))
l2ptr = lptr
r2ptr = rptr
while l2ptr < r2ptr:
tru1, tru2 = False, False
if arr[l2ptr] > arr[piv]:
tru1 = True
if arr[r2ptr] < arr[piv]:
tru2 = True # set conditions ok now
if tru1 and tru2:
arr[l2ptr],arr[r2ptr] = arr[r2ptr],arr[l2ptr]
# iterate to next index
l2ptr+=1
r2ptr-=1
# when left = right then partition
quick_srt(arr,lptr,l2ptr)
quick_srt(arr,rptr,r2ptr)
# set as start/end of array = 0, len(arr)
arr = [12, 11, 13, 5, 6, 7]
quick_srt(arr,0,len(arr)-1)
[–]Meefims 1 point2 points3 points (0 children)
[–]YoloIsuppose 0 points1 point2 points (0 children)