* Sorts by sinus of cell values.
*/
public static void zdemo3() {
Sorting sort = quickSort;
double[] values = {0.5, 1.5, 2.5, 3.5};
DoubleMatrix1D matrix = new DenseDoubleMatrix1D(values);
cern.colt.function.DoubleComparator comp = new cern.colt.function.DoubleComparator() {
public int compare(double a, double b) {
double as = Math.sin(a); double bs = Math.sin(b);
return as < bs ? -1 : as == bs ? 0 : 1;
}
};
System.out.println("unsorted:"+matrix);
DoubleMatrix1D sorted = sort.sort(matrix,comp);
System.out.println("sorted :"+sorted);
// check whether it is really sorted
sorted.assign(cern.jet.math.Functions.sin);
/*
sorted.assign(
new cern.colt.function.DoubleFunction() {
public double apply(double arg) { return Math.sin(arg); }
}