I need to sort some arrays of floats, modify the values, and then construct an array with the original ordering, but the modified values.
In R, I could use the rank()
and order()
functions to achieve this:
v
a vector
v[order(v)]
is sorted
v[i]
goes in the rank(v)
th spot in the sorted vector
Is there some equivalent of these functions in the standard c or c++ libraries? A permutation matrix or other way of encoding the same information would be fine too.
O(n) space and O(nlogn) time would be ideal.