How to calculate the maximum allocated stack memory when recursively calling a function, I created a variable max memory, and I also have a variable memory. Max memory should read the allocated memory during recursive calls to the quicksort function. Please tell me what the condition looks like in which the maximum of the two values is processed (memory and allocated memory recursively)
void QuickSort(int* a, int n)
{
int x, i, j;
int maxmemory = 0;
MEMORY += 7 * sizeof(int);
x = a[n / 2];
i = 0; j = n - 1;
do
{
while (a[i] < x)
{
headoperators++;
i++;
}
headoperators++;
while (x < a[j])
{
headoperators++;
j--;
}
headoperators++;
SIDE_OPERATIONS++;
if (i <= j)
{
swap(a[i], a[j]);
i++;
j--;
}
SIDE_OPERATIONS++;
} while (i < j);
SIDE_OPERATIONS++;
if (j > 0)
QuickSort(a, j + 1);
SIDE_OPERATIONS++;
if (i < n - 1)
QuickSort(a + i, n - i);
}
I don't know exactly how to solve this problem, I'm new to C+=