/* Quicksort that sorts doubles. */ public class quickdouble { private double[] A; // array to be sorted. public quickdouble(int n) // constructor generates random array of size n { A = new double[n]; for (int i=0;i pivot private int partition(int start, int end, int pi) { double pivot = A[pi]; // records value of pivot (pi is the index) int i = start; // used to step through every element of the array int e = start; // used to keep track of end of first paritition double temp; // used to swap values while (i<=end) { if (A[i] <= pivot) // swap it to the first partition, inc e { temp = A[i]; A[i] = A[e]; A[e] = temp; e++; } i++; } // while return e; }//parititon public void qsort(int start, int end) { int pi = findpivot(start,end); // find index of pivot, -1 if non exist if (pi>=0) // pivot exists { int start2 = partition(start,end,pi); // returns start of 2nd paritition qsort(start,start2-1); qsort(start2,end); } // else partition already sorted, so there's nothing to do }//qsort /* test main */ public static void main(String[] args) { int n = Integer.parseInt(args[0]); // length of array to be created long t1, t2, t3; // for timing comparisons quickdouble qsinstance = new quickdouble(n); t1 = System.currentTimeMillis(); qsinstance.qsort(0,n-1); t2 = System.currentTimeMillis(); System.out.println("time to quicksort : "+(t2-t1)+"ms"); //qsinstance.print(); // do not use during timing tests } // main } // quickdouble