Original Post
Alrighty well, I've been attempting to get this annoyingly simply quicksort to work in a program. I won't deny that this is a program for school, but I'm asking that absolutely no one give me the code that will make it work. A) I know its against the rules here, and B) I won't learn a single thing if I just copy/paste the code. I have the method for quicksorting done correctly I'm pretty sure, this is what I have for the method: The issue is that when I call it, I pass in the minimum and maximum numbers (left and right) and it runs fine. Only some of the time do two numbers swap, but when they do its done correctly. The issue is that it only runs once, so in the beginning of the method, if left is greater/equal to right, it exits the method and goes back to main and moves on. I've tried various loops when I call the method so that if it returns early, it will go back into the method with the next two left and right values (left incremented, right decremented), but I must be doing something wrong because it never sorts. I'm just looking for to be pointed in the right direction to get this little devil to work, but I do ask that no one types out the code and just says "Do that", I would rather hear an idea and try to implement it myself. Is a loop the right idea when I initially call the method so if it does get sent back right away, it will change values and go back in? Any help is greatly appreciated! JDDeal [Edited by - TheRealDeal on December 7, 2008 4:11:21 PM]
static void quickSort(int[] a, int left, int right){
if (left >= right)
return;
int i = left;
int j = right;
int pivotValue = a[(left+right)/2];
while (i < j){
while (a < pivotValue)
i++;
while (pivotValue < a[j])
j--;
if (i <= j){
int temp = a;
a = a[j];
a[j] = temp;
i++;
j--;
}
}
quickSort(a, left, j);
quickSort(a, i, right);
}