So, I know how to sort a Java array from intsor floats(or other data types). But what if it was an array of strings String[] arr = {}, where such elements are contained in an array like 2x^2, 4x^4. As you can see, there are several indices with integers that can be sorted.
The way I think sorting this is to combine the number in the index. Sort these numbers, then map each old index to a new index.
I feel that there is a better way.
The essential question is: is there a sorting method that can sort a string array based on an integer with a specific index of each index?
If you're interested, there will be some sample inputs and outputs of the algorithm as such.
Array: {"2x^3","2x^0","1x^1"}
Output:{"2x^3","1x^1","2x^0"}
source
share