How to count comaprisons and swaps in Quicksort in Java?
问题 I have a simple method to sort an array of int with Quicksort. I dont know how to properly count the number of swaps and comparisons, since the algorithm is recursive: public void quicksort(int tablica[], int x, int y) { int i,j,v,temp; i=x; j=y; int swaps=0; int comparisons=0; v=tablica[(x+y) / 2]; while (i<=j) { while (tablica [i] <v) { i++; } while (tablica [j] >v) { j--; } if (i<=j){ temp = tablica [i]; tablica [i]=tablica[j]; tablica [j] = temp; i++; j--; swaps++; } comparisons++; } if