I wouldn't say your code is wrong... like I said, the selection sort can be done in many ways. Here's the algo from
Wikipedia:
for i ← 0 to n-2 do
min ← i
for j ← (i + 1) to n-1 do
if A[j] < A[min] //this is the comparison
min ← j
swap A[i] and A[min]
Wikipedia goes on to explain "selecting the lowest element requires scanning all n elements (this takes n − 1 comparisons) and then swapping it into the first position."
What that means for you is that if you have 10 elements then you'll be doing 10 - 1 comparisons the first time the loops runs, then 9 - 1 comparisons the next time the loop runs and so on. In this way, you can actually use this loop to count the number of comparisons:
int comp = 0;
for (int k = 0; k <= n - 2; k++)
comp += n - 1 - k;
Simply put, each time the loop runs, there will be one less comparison. Also, since you don't ever compare the first element with itself and you don't need to compare the last element with anything, the
k loop runs to
n - 2 where
n is the number of elements.
And in retrospect, when I said: "There are other methods of doing the selection sort that would seem more applicable to counting the number of comparisons," I think I was mistaken.