I'm trying to figure out where a proper place to put a comparison counter to count the number of 'comparisons' made in a quick sort is. This is my code so far, I have one counter where I think it should go, but I'm not sure if it should place it in more than one location:
void partition(vector<int>& array, int first, int last, int &pivotIndex, int &comparisons)
{
int pivot = array[first];
int lastS1 = first;
int firstUnknown = first +1;
for (; firstUnknown <= last; ++firstUnknown)
{
//comparisons++;
if(array[firstUnknown] < pivot)
{
++lastS1;
swap(array[firstUnknown], array[lastS1]);
comparisons++;
}
}
swap(array[first], array[lastS1]);
pivot = lastS1;
}
Any help would be appreciated! Thanks in advance!