I have two vectors, vec and p, such that p is a vector of pointers to different locations in vec.
So something like:
p[0] = &vec[12]
p[1] = &vec[20]
p[3] = &vec[1]
etc .. p the size will always be less than or equal to vec and will not contain duplicate links to the same place in vec.
What I would like to have is some data structure through which I can iterate to get the dereferenced p values in the order of the index they point to in a. Thus, for the above example, the result will have to go through the order vec [1], vec [12], vec [20].
I know that I can get a position in vec, since p indicates that it does something like p[i] - &vec[0], and probably can implement this using std :: sort and a custom comparison function, but I feel there is more efficient way to do this than O (nlogn) sort functions. I could be wrong about that too.
Thanks for any help!
source
share