Skip to Main Content

New to Java

Announcement

For appeals, questions and feedback about Oracle Forums, please email oracle-forums-moderators_us@oracle.com. Technical questions should be asked in the appropriate category. Thank you!

quicksort

807599Feb 21 2007 — edited Feb 22 2007
Hi 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
Comments
Locked Post
New comments cannot be posted to this locked post.
Post Details
Locked on Mar 22 2007
Added on Feb 21 2007
4 comments
306 views