You need to somehow keep the information about the index.
I can see two ways of doing this :
1-Since you represent your point by a vector, you can had another dimension that will represent the orginal index :
//Adding index info, inportant that your index be the last dimension , otherwise the sort is incorrect
for(auto point = vector.begin(),unsigned int index=0;point != vector.end(); ++point,++index){
point->push_back(index)
};
Then sort the same way you are doing now :
sort(vector.begin(), vector.end())
and you access the original index with A[0][n]
The cool thing about that is that it allow you to keep track of the index in a very convenient way, but you need to be able to modify the representation of your point.
2- The other way is to have an external table of indices and sort that using custom comp. operator :
you start by creating a vector of indices
std::vector indices(vector.size());
for(unsigned int index =0;index != indicies.size(); ++point){
indicies[index] = index ;
};
//and sort...
std::sort(indices.begin(),indices.end(),[&](unsigned int i,unsigned int j) { return vector[i] < vector[j]})
now you need an additional level of indirection to go trough your points in the sorted order :
A[indices[0]],A[indices[1]],...
So the original position of A[indices[x]] is simply x
The main to remember between those two ways of doing it is that in the first you move your data around and not in the second , depending on what you are doing on your points, one might be better that the order