Note that there are some explanatory texts on larger screens.

plurals
  1. POQuicksort not working
    primarykey
    data
    text
    <p>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</p> <pre><code>public static void hybridQuicksort( int[] a, int start, int end ) { final int MIN = 13; if ( end - start &gt;= 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 &lt;= down ) { while ( a[up] &lt;= pivot) up++; while ( a[down] &gt; pivot) down--; if ( up &lt;= 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]; } </code></pre>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload