quicksort
807599Feb 21 2007 — edited Feb 22 2007Hi i am having some difficulty with the quicksort partition method. i have to find copies and comparisons for arrays[20} etc. I have managed to get the comparisons and copies for the selection sort but cannot seem to get this part!!Any advice?Or hints please?
static void quickSort (Comparable[] a,
int left, int right){
if (left < right)
{
int p = partition(a, left, right);
quickSort(a, left, p-1);
quickSort(a, p+1, right);
}
}
private static int partition
(Comparable[] a, int left, int right) {
Comparable pivot = a[left]; int p =left;
for (int r = left + 1; r <= right; r++) {
int comp = a[r].compareTo(pivot);
if (comp < 0) {
a[p] = a[r]; a[r] = a[p+1]; a[p+1]= pivot;
p++;
}
}
return p;
}
Message was edited by:
fiorentina1983