Quick code:
import sys
sys.setrecursionlimit(100000)
def mysqort(arr, low, high):
if low >= high:
return
i = low
j = high
base = arr[low]
while(i<j):
while(i<j and arr[j] > base):
j -= 1
if(i<j):
arr[i] = arr[j]
i = i + 1
while(i<j and arr[i] < base):
i += 1
if(i<j):
arr[j] = arr[i]
j -= 1
arr[i] = base
mysqort(arr,low,i-1)
mysqort(arr,i+1,high)
-sharp10000
arr = list(range(10000))
-sharp
arr.reverse()
-sharp
mysqort(arr,0,9999)
-sharp
print(arr)
I am surprised that 10000 numbers can not be sorted. It is said on the Internet that there is a limit on the depth of recursion. Sys.setrecursionlimit (100000), which is also set here, why does the fast row of 10000 numbers overflow the stack?
wrote another recursion:
import sys
sys.setrecursionlimit(100000000)
def rec(n):
print(n)
rec(n+1)
rec(1)
print to 8657 starts to report stack overflow problems