My program works alright for integer array, but not float array. How can I change the program so that I can get the original position of each element in the float array after sorting? Let's say my float array is {5.0f,10.0f,1.0 f,15.0f}.
Here's my code:
Here's my code:
Code:
import java.util.*;
public class SortArrays
{
public static void main(String args[])
{
Integer[] score = {5, 10, 0, 1, 15};
ArrayList Values = new ArrayList();
HashMap OriginalPos = new HashMap();
for(int i=score.length-1;i>=0;i--)
{
OriginalPos.put(new Integer(score[i]), new Integer(i));
Values.add(new Integer(score[i]));
}
Collections.sort(Values);
for(int i=Values.size()-1;i>=0;i--)
{
int val = ((Integer)(Values.get(i))).intValue();
System.out.print("" + val + " ");
System.out.println(OriginalPos.get(new Integer(val)));
}
}
}
Comment