public static int partition1(int [] A, int lo, int hi) {
int pivot,i,j;
pivot = Randnums.randnum(lo,hi-1);
int mid = pivot;
//locate pivot in well known position --
at front of the list
swap(A, lo, pivot);
i = lo + 1;
j= hi - 1;
while (i <= j) {
count+=3; //one for exiting each of the 2 while loops and the if statement
while ((i <= j) && A[i] <= A[lo]) {
count+=2; cmprs++;
i++;
}
while (A[j] > A[lo]) {
count++; cmprs++;
j--;
}
if (i < j){
count++;
swap(A, i, j);
}
}
//put pivot into its right position
swap(A, lo, j);
count++;
return j;
} // end partition1;
public static void quicksort(int [] A, int lo, int hi) {
int split;
count++;
if ((hi - lo) > 1) {
split = partition1(A,lo,hi);
quicksort(A,lo,split);
quicksort(A,split+1,hi);
}
} // end quicksort