Java Utililty Methods Array Sort

List of utility methods to do Array Sort

Description

The list of methods to do Array Sort are organized into topic(s).

Method

int[]sortedPointersInto(double d[])
sorted Pointers Into
return sortedPointersInto_tryingToImproveSpeed(d);
int[]sortedPointersInto_tryingToImproveSpeed(final double d[])
sorted Pointers Inttrying To Improve Speed
for (int i = 0; i < d.length; i++) {
    double x = d[i];
    if (x != x) { 
        d[i] = Double.MAX_VALUE;
Integer Ints[] = new Integer[d.length];
for (int i = 0; i < d.length; i++)
...
int[]sortedPointersInto_usingStrictfp(final double d[])
strictfp needed to avoid violating Comparator.
Integer Ints[] = new Integer[d.length];
for (int i = 0; i < d.length; i++)
    Ints[i] = i;
Comparator<Integer> compare = new Comparator<Integer>() {
    public strictfp int compare(Integer x, Integer y) {
        double xd = d[x], yd = d[y];
        if (xd < yd)
            return -1;
...
voidsortEigenValues(int n, double[] d, double[][] v)
sort Eigen Values
for (int i = 0; i < n - 1; i++) {
    int k = i;
    double p = d[i];
    for (int j = i + 1; j < n; j++) {
        if (d[j] < p) { 
            k = j;
            p = d[j];
    if (k != i) {
        d[k] = d[i]; 
        d[i] = p;
        for (int j = 0; j < n; j++) {
            p = v[j][i];
            v[j][i] = v[j][k];
            v[j][k] = p;
int[]sortIndex(double[] A)
sort Index
double[] sortedA = new double[A.length];
int[] index = new int[A.length];
double valueToInsert;
int holePos;
for (int i = 0; i < sortedA.length; i++) {
    valueToInsert = A[i];
    holePos = i;
    while (holePos > 0 && valueToInsert < sortedA[holePos - 1]) {
...
int[]sortIndex(double[] doubleArray)
sort Index
return sortIndex(_arrayToArrayList(doubleArray));
Integer[]sortIndexes(final T[] array)
sort Indexes
Integer[] idx = new Integer[array.length];
for (int i = 0; i < array.length; i++)
    idx[i] = i;
Arrays.sort(idx, new Comparator<Integer>() {
    public int compare(final Integer o1, final Integer o2) {
        return array[o1].compareTo(array[o2]);
});
...
Integer[]sortIndexesDescending(final double[] in)
Returns an array of indexes into the given array, where the indexes are ordered such that they sort their targets from greatest to least.
Integer[] result = new Integer[in.length];
for (int i = 0; i < result.length; i++)
    result[i] = i;
Comparator<Integer> comparator = new Comparator<Integer>() {
    @Override
    public int compare(Integer i1, Integer i2) {
        return Double.compare(in[i1], in[i2]) * -1;
};
Arrays.sort(result, comparator);
return result;
int[]sortindices(double[] x)
Sort two arrays simultaneously, using the sort order of the values in the first array to determine the sort order for both arrays.
double a[] = new double[x.length];
int b[] = new int[a.length];
for (int i = 0; i < a.length; ++i) {
    a[i] = x[i];
    b[i] = i;
mergesort(a, b, 0, a.length - 1);
return b;
...
int[]sortIndices(float[] main)
Sort an array in ascending order, but return the index of each sorted element in the original array
int[] index = new int[main.length];
for (int i = 0; i < index.length; i++) {
    index[i] = i;
quicksort(main, index, 0, index.length - 1);
return index;