When I run my function on a small array, it works fine. However when I use a large array, I keep getting stack overflow. Is it due to my incorrect logic in my code? or is it just taking a long time?
void RecursiveSort(T data[], int first, B last)
{
// Sorts the array elements a[first] through a[last] recursively.
// base case is if first and last are the same, which means we
// have no subarrays left to do
if (first < last)
{
int minIndex = first;
// replace first index of array with smallest of values in the array
for (int index = first+1; index < last; index++)
{
if (data[index] < data[minIndex])
// swap values
minIndex = index;
}
int temp = data[first];
data[first] = data[minIndex];
data[minIndex] = temp;
RecursiveSort(data, first + 1, last);
}
}