Here is a bit of code that ranks elements of a double array:
public class Rank {
public static enum Dir {
Ascending(1),
Descending(-1);
int side;
Dir(int i) {
side = i;
}
}
/**
* Rank elements of an array.
*
* @param dir : direction to rank elements in.
* @param data : elements of the array.
* @return
*/
public static Integer[] rank(final Dir dir, final double[] data) {
final Integer[] idx = new Integer[data.length];
for (int i = 0; i < data.length; i++) {
idx[i] = i;
}
Arrays.sort(idx, new Comparator<Integer>() {
@Override
public int compare(final Integer o1, final Integer o2) {
return Double.compare(dir.side * data[o1], dir.side *
data[o2]);
}
});
return idx;
}
public static void main(String[] args) {
final double[] data = {1.7f, -0.3f, 2.1f, 0.5f};
final Integer[] idx = rank(Dir.Descending, data);
System.out.println(Arrays.toString(idx));
}
}
On Thu, Sep 19, 2013 at 6:14 PM, Ajo Fod <[email protected]> wrote:
> It currently has the maximum of a double array.
>
> -Ajo.
>