재귀함수 없이 코드를 돌렸을 때는
def Qsort(lt, rt):
pos = lt
pivot = arr[rt]
for i in range(lt, rt):
if arr[i] <= pivot:
arr[i], arr[pos] = arr[pos], arr[i]
pos += 1
arr[rt], arr[pos] = arr[pos], arr[rt]
if __name__ == '__main__':
arr = [45, 21, 23, 36, 15, 67, 11, 60, 20, 33]
print('Before sort : ', end = ' ')
print(arr)
Qsort(0, 9)
print()
print('After sort : ', end = ' ')
print(arr)
Before sort : [45, 21, 23, 36, 15, 67, 11, 60, 20, 33]
After sort : [21, 23, 15, 11, 20, 33, 36, 60, 45, 67]
로 결과가 잘 나왔습니다.
그런데
def Qsort(lt, rt):
pos = lt
pivot = arr[rt]
for i in range(lt, rt):
if arr[i] <= pivot:
arr[i], arr[pos] = arr[pos], arr[i]
pos += 1
arr[rt], arr[pos] = arr[pos], arr[rt]
Qsort(lt, pos-1)
Qsort(pos+1, rt)
재귀함수를 추가하니까
RecursionError: maximum recursion depth exceeded in comparison
RecursionError가 발생했고
import sys
sys.setrecursionlimit(10**6)을 추가해주니
Before sort : [45, 21, 23, 36, 15, 67, 11, 60, 20, 33]
만 나오고 After sort에 대한 결과가 안나옵니다ㅠㅠ
그냥 컴퓨터 문제일까요..?