I have tried everything. Even have found an online example that is exactly like mine. Every time I run this quick sort it results in an infinite loop, and I am so stuck. Can someone please help? I'm simply passing an array through like normal, and cant get this think to work. Also ignore the timing aspect, thats for the project, timing the sort.
template<typename T>
void quickSort(T list[], int lowerBound, int upperBound)
{
cout.setf(ios::fixed | ios::showpoint);
cout.precision(16);
TimerSystem timer;
timer.startClock();
upperBound = upperBound - 1;
long int i = lowerBound;
long int j = upperBound;
long int pivot = list[(lowerBound + upperBound) / 2];
T temp;
while (i <= j)
{
while (list[i] < pivot)
{
i += 1;
}
while (list[j] > pivot)
{
j -= 1;
}
if (i <= j)
{
temp = list[i];
list[i] = list[j];
list[j] = temp;
i += 1;
j -= 1;
}
}
if (lowerBound < j)
{
quickSort(list, lowerBound, j);
}
if (i < upperBound)
{
quickSort(list, i, upperBound);
}
cout << "USE FINAL TIME RECORDING!! QuickSort took " << timer.getTime() << "seconds to sort" << endl;
cout << endl;
}