staticvoid selectsort(int[] data, int n)
{
int i, j;
for (i = 0; i < n; i++)
{
int min = i;
for (j = i + 1; j < n; j++)
if (data[j] < data[min])
min = j; //find min value
//then swap it with the beginning item of the unsorted list
int temp = data[i];
data[i] = data[min];
data[min] = temp;
}
}
}
}
You have comparsion on line 15. This is only one. You just need some kind of counter to store amount and increment it every time this line is executed.
One way to do
1) make function return int so we can get access to count of comparsions.
2) add int comp = 0; at the very begining of your function.
3) Change line 15 to: if (++comp, data[j] < data[min])
4) add return comp; at the very end of your function