Java Array Sort sortIndex(double[] A)

Here you can find the source of sortIndex(double[] A)

Description

sort Index

License

Open Source License

Declaration

public static int[] sortIndex(double[] A) 

Method Source Code

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

public class Main {
    public static int[] sortIndex(double[] A) {

        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];/*from   www  .  ja  v  a 2s  .c om*/
            holePos = i;
            while (holePos > 0 && valueToInsert < sortedA[holePos - 1]) {
                sortedA[holePos] = sortedA[holePos - 1];
                index[holePos] = index[--holePos];
            }
            sortedA[holePos] = valueToInsert;
            index[holePos] = i;
        }
        return index;
        /*
        int[] retindex=new int[A.length];
        retindex[0]=index[0];
        int k=1;
        for (int i=1;i<sortedA.length;i++){
           if (sortedA[i]>sortedA[i-1]){
        retindex[k++]=index[i];            
           }
        }
            
        return Arrays.copyOf(retindex, k);
        */
    }
}

Related

  1. sortedMerge(int[] aIds, double[] aVals, int[] bIds, double[] bVals, int[] resIds, double[] resVals)
  2. sortedPointersInto(double d[])
  3. sortedPointersInto_tryingToImproveSpeed(final double d[])
  4. sortedPointersInto_usingStrictfp(final double d[])
  5. sortEigenValues(int n, double[] d, double[][] v)
  6. sortIndex(double[] doubleArray)
  7. sortIndexes(final T[] array)
  8. sortIndexesDescending(final double[] in)
  9. sortindices(double[] x)