Greetings
The quicksort i am building works for only aprox 50000 element in a list.
If i go above that i will run out of memory and the program will crash.
This is only when i use the median of three or left as my pivot element.
When i use random i can use lists up to atleast 1 million elements.
Is there a way to take care of the memory loss without the need of rewriting everything?
the pivotType is of user input and is sent along. And the array goes from nrOfElements -> 1.
If there is a need for more of my code, please do tell.
array = (int *)malloc(nrOfElements * sizeof(int));
void quickSort(int array[], int left, int right, int pivotType) {
int pivotElement, i, j;
if(left < right) {
if (pivotType == 1)
pivotElement = leftPivot(array, left, right);
if (pivotType == 2)
pivotElement = medianOfThreePivot(array, left, right);
if (pivotType == 3)
pivotElement = randomPivot(array, left, right);
i = left+1;
j = right;
while(i <= j) {
while(i <= right && array[i] <= pivotElement)
i++;
while(j >= left && array[j] > pivotElement)
j--;
if (i < j)
swapElement(&array[i], &array[j]);
}
swapElement(&array[left], &array[j]);
quickSort(array,left,j-1, pivotType);
quickSort(array,j+1,right, pivotType);
}
}
//after all quicksorts are done with all subarrays the
free(array); is called