I am trying to sort (decreasing) an array of integers but keeping track of the original index.
I mean, for example if I have this array:
b[
The following answer provides the main steps to overcome the issue explained in the question without details code provided.
Class that has two attributes value and index. where value is the original attribute value and index is the position before sorting.ArrayList of this Class.Class with the wanted value and index.Note: one possible way to set the index value is to iterate through the Arraylist and set the value of index using loop index.
sort the Arraylist using specialComparable based on value attribute.
now after sorting you can know the previousindex of any entry by invoking its index attribute.