Java Array Sort sortIndexesDescending(final double[] in)

Here you can find the source of sortIndexesDescending(final double[] in)

Description

Returns an array of indexes into the given array, where the indexes are ordered such that they sort their targets from greatest to least.

License

Open Source License

Parameter

Parameter Description
array a parameter

Declaration

public static Integer[] sortIndexesDescending(final double[] in) 

Method Source Code

//package com.java2s;
//License from project: Open Source License 

import java.util.Arrays;
import java.util.Comparator;

public class Main {
    /**//from w ww .  j a  v a2s . c o  m
     * Returns an array of indexes into the given array, where the indexes are ordered such that
     * they sort their targets from greatest to least.
     * @param array
     * @return
     */
    public static Integer[] sortIndexesDescending(final double[] in) {
        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;
    }
}

Related

  1. sortedPointersInto_usingStrictfp(final double d[])
  2. sortEigenValues(int n, double[] d, double[][] v)
  3. sortIndex(double[] A)
  4. sortIndex(double[] doubleArray)
  5. sortIndexes(final T[] array)
  6. sortindices(double[] x)
  7. sortIndices(float[] main)
  8. sortInPlace(final double[] v, final int i, final int j)
  9. sortInPlace(int[] array)