This is all my code for my quicksort method, it works on a set of 21 numbers, but not on my real data set, which is about 100000. I have no idea what is wrong, I've been fiddling for two hours and it is due soon! Any help would be very welcome
public static void hybridQuicksort( int[] a, int start, int end )
{
final int MIN = 13;
if ( end - start >= MIN )
{
int pivot = findPivot( a, start, end );
pivot = partition ( a, start, end, pivot );
hybridQuicksort( a, start, pivot - 1 );
hybridQuicksort( a, pivot + 1, end);
}
else
{
insertionSort( a, start, end );
}
}
//partitions the array based on the pivot
public static int partition( int[] a, int start, int end, int pivot )
{
int up = start + 1;
int down = end;
while ( up <= down )
{
while ( a[up] <= pivot)
up++;
while ( a[down] > pivot)
down--;
if ( up <= down )
swap( a, up, down );
}
swap( a, start, down );
return up;
}
//finds the first, middle, middle of first and middle, middle of middle and last
//and last numbers and sets their median as the pivot
public static int findPivot( int[] a, int start, int end )
{
//swap the 4 numbers to the start of the array, leaving the first as is
swap( a, start + 1, end - 1 );
swap( a, start + 2, (start + end) / 2);
swap( a, start + 3, end / 4);
swap( a, start + 4, (end / 2) + (end / 4) );
//sort the 5 numbers
insertionSort( a, 0, 5 );
//swap the median to the front, that's the pivot
swap( a, start, start + 2 );
//return the pivot
return a[start];
}