is there a way to sort an array and store the result in a linked list with the original array positions referenced by the list?
so
0 bbb 1 aaa 2 ccc
would become a linked list
1 aaa 0 bbb 2 ccc
Thanks
is there a way to sort an array and store the result in a linked list with the original array positions referenced by the list?
so
0 bbb 1 aaa 2 ccc
would become a linked list
1 aaa 0 bbb 2 ccc
Thanks
You can just use a TreeMap:
final SortedMap<String, Integer> map = new TreeMap<String, Integer>(array.length);
for (int index = 0; index < array.length; i++)
map.put(array[index], index);
The keys are therefore the strings, in order, and the positions in the original aray are the values. But storing a String and its origin position requires a dedicated structure. Or maybe the Map.Entry<String, Integer> entries for the map are enough for your needs. It depends on what you want to do.