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!

Stack OverFlow Problem with QuickSort Partition, please help.

807601Mar 20 2008 — edited Mar 20 2008
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.
Comments
Locked Post
New comments cannot be posted to this locked post.
Post Details
Locked on Apr 17 2008
Added on Mar 20 2008
16 comments
1,032 views