Here you can find the source of sortArray(double[] array)
Parameter | Description |
---|---|
array | The array |
public static int[] sortArray(double[] array)
//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; } }