N
nandor.sieben
I have a vector of integers something like v=(2,1,5,4). I'd like to
create a vector containing the indices in order of the values of this
vector. So the output would be (1,0,3,2). Note that
v[0]<v[1]<v[3]<v[2]. What's the easiest/most efficient way to do
this?
Is there something like a parallel sort that takes two vectors as its
input, sorts the first one and makes the same changes two the second
vector. So if v=(2,1,5,4) and w=(0,1,2,3) then parallel_sort(v,w)
would change this into v=(1,2,4,5) and w=(1,0,3,2).
Of course I can do this on my own with loops but I think that would
not be very efficient. I cannot match the built in STL sort algorithm.
What I'd like to know if there is an effective way of doing this with
the STL algorithms.
create a vector containing the indices in order of the values of this
vector. So the output would be (1,0,3,2). Note that
v[0]<v[1]<v[3]<v[2]. What's the easiest/most efficient way to do
this?
Is there something like a parallel sort that takes two vectors as its
input, sorts the first one and makes the same changes two the second
vector. So if v=(2,1,5,4) and w=(0,1,2,3) then parallel_sort(v,w)
would change this into v=(1,2,4,5) and w=(1,0,3,2).
Of course I can do this on my own with loops but I think that would
not be very efficient. I cannot match the built in STL sort algorithm.
What I'd like to know if there is an effective way of doing this with
the STL algorithms.