Here you can find the source of quicksort(double[] main, int[] index)
public static void quicksort(double[] main, int[] index)
//package com.java2s; //License from project: Open Source License public class Main { public static void quicksort(double[] main, int[] index) { quicksort(main, index, 0, index.length - 1); }//from w ww .j av a2s.c o m public static void quicksort(double[] a, int[] index, int left, int right) { if (right <= left) return; int i = partition(a, index, left, right); quicksort(a, index, left, i - 1); quicksort(a, index, i + 1, right); } private static int partition(double[] a, int[] index, int left, int right) { int i = left - 1; int j = right; while (true) { while (less(a[++i], a[right])) // find item on left to swap ; // a[right] acts as sentinel while (less(a[right], a[--j])) // find item on right to swap if (j == left) break; // don't go out-of-bounds if (i >= j) break; // check if pointers cross exch(a, index, i, j); // swap two elements into place } exch(a, index, i, right); // swap with partition element return i; } private static boolean less(double x, double y) { double first = Double.isNaN(x) ? Double.NEGATIVE_INFINITY : x; double second = Double.isNaN(y) ? Double.NEGATIVE_INFINITY : y; return (first > second); } private static void exch(double[] a, int[] index, int i, int j) { double swap = a[i]; a[i] = a[j]; a[j] = swap; int b = index[i]; index[i] = index[j]; index[j] = b; } }