So I know how to sort a Java array of ints or floats (or other data types). But what if it was a string array String[] arr = {} where the array contained elements like 2x^2, 4x^4. As you can see, there are several indices that have integers, which could be sorted.
The way I would think to sort this is to splice out the number at an index. Sort those numbers, then map each old index to the new index.
I feel like there is a better way.
The essential question: Does a sorting method exist that can sort a string array based on an integer at a certain index of each index?
If you are wondering, here would be some sample inputs and outputs of an algorithm as such.
Array: {"2x^3","2x^0","1x^1"}
Output:{"2x^3","1x^1","2x^0"} // Sorted based on last index