I need to do the following:
Given an std::vector
of int
I need to replace each int
by the index that it would be in if the vector were sorted.
I will try to explain it better with an example.
Input: {22, 149,31}
Output: {2, 0, 1}
(Note that in the sorted vector {149, 31, 22} the 22 is in the index 2 of the sorted vector, the 149 is in index 0, and the 31 is in index 1)
I hope I make the algorithm clear.
Is this implemented somehow in the STL C++11 library? Has this algorithm a name? Can you offer any ideas to implement it elegantly?