public static void sort(double[] x, int start, int end)
    {
        int a = start;
        int n = end-start;
        if (n < 7)/* Insertion sort on smallest arrays */
        {
            insertionSort(x, a, end);
            return;
        }
        
        int pm = a + (n/2);  /* Small arrays, middle element */
        if (n > 7)
        {
            int pl = a;
            int pn = a + n - 1;
            if (n > 40) /* Big arrays, pseudomedian of 9 */
            {        
                int s = n / 8;
                pl = med3(x, pl, pl + s, pl + 2 * s);
                pm = med3(x, pm - s, pm, pm + s);
                pn = med3(x, pn - 2 * s, pn - s, pn);
            }
            pm = med3(x, pl, pm, pn); /* Mid-size, med of 3 */
        }
        double pivotValue = x[pm];

        int pa = a, pb = pa, pc = end - 1, pd = pc;
        while (true)
        {
            while (pb <= pc && x[pb] <= pivotValue)
            {
                if (x[pb] == pivotValue)
                    swap(x, pa++, pb);
                pb++;
            }
            while (pc >= pb && x[pc] >= pivotValue)
            {
                if (x[pc] == pivotValue)
                    swap(x, pc, pd--);
                pc--;
            }
            if (pb > pc)
                break;
            swap(x, pb++, pc--);
        }

        
        int s;
        int pn = end;
        s = Math.min(pa - a, pb - pa);
        vecswap(x, a, pb - s, s);
        s = Math.min(pd - pc, pn - pd - 1);
        vecswap(x, pb, pn - s, s);

        //recurse 
        if ((s = pb - pa) > 1)
            sort(x, a, a+s);
        if ((s = pd - pc) > 1)
            sort(x, pn - s, pn);
        
    }
public static void sort ( double [ ] x , int start , int end ) { int a = start ; int n = end - start ; if ( n < 7 ) { insertionSort ( x , a , end ) ; return ; } int pm = a + ( n / 2 ) ; if ( n > 7 ) { int pl = a ; int pn = a + n - 1 ; if ( n > 40 ) { int s = n / 8 ; pl = med3 ( x , pl , pl + s , pl + 2 * s ) ; pm = med3 ( x , pm - s , pm , pm + s ) ; pn = med3 ( x , pn - 2 * s , pn - s , pn ) ; } pm = med3 ( x , pl , pm , pn ) ; } double pivotValue = x [ pm ] ; int pa = a , pb = pa , pc = end - 1 , pd = pc ; while ( true ) { while ( pb <= pc && x [ pb ] <= pivotValue ) { if ( x [ pb ] == pivotValue ) swap ( x , pa ++ , pb ) ; pb ++ ; } while ( pc >= pb && x [ pc ] >= pivotValue ) { if ( x [ pc ] == pivotValue ) swap ( x , pc , pd -- ) ; pc -- ; } if ( pb > pc ) break ; swap ( x , pb ++ , pc -- ) ; } int s ; int pn = end ; s = Math . min ( pa - a , pb - pa ) ; vecswap ( x , a , pb - s , s ) ; s = Math . min ( pd - pc , pn - pd - 1 ) ; vecswap ( x , pb , pn - s , s ) ; if ( ( s = pb - pa ) > 1 ) sort ( x , a , a + s ) ; if ( ( s = pd - pc ) > 1 ) sort ( x , pn - s , pn ) ; }
Performs sorting based on the double values natural comparator.
{@link Double#NaN} values will  not be handled appropriately.

@param x the array to sort
@param start the starting index (inclusive) to sort
@param end the ending index (exclusive) to sort