Suppose I have the following setup:
double[] vectorUsedForSorting = new double[] { 5.8,6.2,1.5,5.4 }
double[] vectorToBeSorted = new double[] {1.1,1.2,1.3,1.4}
I would like to sort vectorToBeSorted based on the natural numerical ordering of vectorUsedForSorting.
For example, the natural ordering would be [1.5,5.4,5.8,6.2] which corresponds to indices [2,3,0,1], which would mean I want the output of the sorting function to be [1.3,1.4,1.1,1.2].
How do I do this in the most absolute efficient/fast possible way? I am mostly concerned with time-complexity since I will be doing this for 1,000,000 length arrays.
A large bonus will be awarded to a fast/efficient answer.