I have a program that is supposed to count the number of 'comparisons' during a selection sort. I'm having trouble trying to determine what a 'comparison' is considered!
It runs the sort properly and sorts in ascending order, but I'm not sure where to put the comparison counter. I'm wondering if maybe it should be right below the swap statement instead. Any help would be greatly appreciated! My code is as follows:
void selectionSort(int &arraysize, int array[], int &comparisons)
{
int last;
int bigIndex;
comparisons = 0;
for(last = arraysize-1; last >= 1; last--)
{
bigIndex = 0;
for (int j = 1; j <= last; j++)
{
//comparison counter
//comparisons+=1;
if (array[j] > array[bigIndex])
{
bigIndex = j;
}
}
if (bigIndex !=last)
{
swap(array[last], array[bigIndex]);
}
}
}