You generally only count element comparisons, not integer comparisons, even though the elements in your array are integers.
To make this make a bit more sense - if you were to change the array to an array of strings (for example), only count the number of string comparisons. String comparisons are generally way more expensive than integer comparisons (and it would be even more so if you have a large object with many fields), so only counting these makes sense.
So these compare elements:
a[left] > a[i]
a[right] > a[largest]
These just compare integers:
i >= 0
left <= n
right <= n
largest != i
i > 0
I'd suggest writing a compare
function that also increases your count (and just replacing the above 2 element comparisons with it and removing other places where you increase the count). I also suggest sticking to convention in what the function returns.
Your function can just look like this: (pre-Java 7 you'll have to use Integer.valueOf(a).compareTo(b)
instead)
int compare(int a, int b)
{
counter++;
return Integer.compare(a, b);
}
So a[left] > a[i]
would become compare(a[left], a[i]) > 0
, and similarly for the other one.
A Comparator would make for a more generic solution, but it is probably a bit overkill in this case.