Java Array Sort sortArray(double[] array)

Here you can find the source of sortArray(double[] array)

Description

sort Array

License

Open Source License

Parameter

Parameter Description
array The array

Return

The sorted in ascending order indices of the given array

Declaration

public static int[] sortArray(double[] array) 

Method Source Code

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

public class Main {
    /**//w  ww. jav a 2  s  .  co  m
     * @brief Returns the sorted in ascending order indices of a given array
     *
     * @param array
     *     The array
     *
     * @return The sorted in ascending order indices of the given array
     */
    public static int[] sortArray(double[] array) {
        int length = array.length;
        double[] arrayClone = new double[length];

        System.arraycopy(array, 0, arrayClone, 0, length);

        int[] indices = new int[length];
        for (int i = 0; i < length; i++) {
            indices[i] = i;
        }

        for (int i = 0; i < length; i++) {
            for (int j = 1; j < length - i; j++) {
                if (arrayClone[j - 1] > arrayClone[j]) {
                    double temp = arrayClone[j - 1];
                    arrayClone[j - 1] = arrayClone[j];
                    arrayClone[j] = temp;

                    int tempIndex = indices[j - 1];
                    indices[j - 1] = indices[j];
                    indices[j] = tempIndex;
                }
            }
        }

        return indices;
    }
}

Related

  1. sortableBytesToInt(byte[] encoded, int offset)
  2. sortAccording(float[] ary, Integer[] sortOrder)
  3. sortAccording2(int[] ary, Integer[] sortOrder)
  4. sortAlleleCount(int[] count)
  5. SortAndConcatenateStringArray(String StrArray[], String Separator)
  6. sortArray(int[] a)
  7. sortArray(int[] array)
  8. sortArrayAndReturnIndex(double[] p, String t)
  9. sortByFirst(int[] array1, int[] array2)