I have a Quicksort method that keeps running into a Stack OverFlow error when it attempts to partition.
Here are my methods:
public static void quickSort(int[] a){
int from = 0;
int to = a.length - 1;
sort(a, from, to);
}
private static int partition(int[] a, int from, int to){
int pivot = a[from];
int i = from - 1;
int j = to + 1;
while (i < j){
i++; while (a[i] < pivot) i++;
j--; while (a[j] > pivot) j--;
if (i < j) swap(a, i, j);
}
return j;
}
private static void sort(int[] a, int from, int to){
if (from >= to) return;
int p = partition(a, from, to); // eclipse tells me my error is here.
sort(a, from, p);
sort(a, p + 1, to); // I also have an error here.
}
Eclipse points to the sort method as the source of my error, which itself points to my attempting to partition the sucker, so I don't know what's up. It's probably something stupid, but I'm lost, so any help is appreciated.