If I want to sort via the following QuickSort algorithm I get either a "RecursionError: maximum recursion depth exceeded in comparison" failure, or if I set the recursion limit much higher, Python stops working after it sortied via BubbleSort with (Process finished with exit code -1073741571 (0xC00000FD)). Does anyone have a idea, how i can fix this problem
Set recursion limit higher
import time
import random
from sys import setrecursionlimit
#setrecursionlimit(1000000)
#------------------------------Sortieralgorithmen-----------------------------------------------
#-----------------------------------------------------------------------------------------------
def bubbleSort(array):
length = len(array)
for sorted in range(length):
for j in range(0, length-sorted-1):
if array[j] > array[j+1] :
array[j], array[j+1] = array[j+1], array[j]
def help(array, low, high):
pivot = array[low]
fromhigh = high
fromlow = low
while True:
while(array[fromhigh]>pivot):
fromhigh = fromhigh-1
while(array[fromlow]<pivot):
fromlow = fromlow+1
if(fromlow<fromhigh):
array[fromlow], array[fromhigh] = array[fromhigh], array[fromlow]
else:
return fromhigh
def quickSort(array, low, high):
if (low<high):
pivot = help(array, low, high)
quickSort(array, low, pivot)
quickSort(array, pivot + 1, high)
#--------------------------------Zeitmessung-----------------------------------------------------
#------------------------------------------------------------------------------------------------
numb_elements = 6000
sortedarray = []
for i in range (0,numb_elements):
sortedarray.append(i)
notsortedarray = random.sample(range(0,numb_elements),numb_elements)
copy1 = sortedarray.copy()
before = time.time()
bubbleSort(copy1)
after = time.time()
total = after-before
print("Bubblesort sortiertes Array:\t\t" + str(total))
copy2 = notsortedarray.copy()
before = time.time()
bubbleSort(copy2)
after = time.time()
total = after-before
print("Bubblesort nicht sortiertes Array:\t" + str(total))
copy3 = sortedarray.copy()
before = time.time()
quickSort(copy3, 0, len(copy3)-1)
after = time.time()
total = after-before
print("QuickSort sortiertes Array:\t\t\t" + str(total))
copy4 = notsortedarray.copy()
before = time.time()
quickSort(copy4, 0, len(copy4)-1)
after = time.time()
total = after-before
print("QuickSort nicht sortiertes Array:\t" + str(total)+"\t (Worst Case)")