Lets say you have the vector(same as your comment on my answer’s post),
3 5 5 6
2 2 5 8
3 1 4 5
8 7 6 4
I want to sort the rows only based on the 2nd column such that my output is:
3 1 4 5
2 2 5 8
3 5 5 6
8 7 6 4
Note,how this output came, we are just sorting the coloumn1(0-indexed) i.e. 5 2 1 7. The entries The smallest element in the vector is 1, i.e. row 2 then 2(row 1) then 0(row0), then 7(row 3). Insert entries in the map as the pair <element, row number> If you don’t know that, let me know I’ll put that in code. As we know, entries in the map are sorted by their first value and this is logarithmic. What we’ll have in map now is <element, row number>. This will now tell you which row needs to be the first one in your sorted vector and which needs to be last or at what place. Still not clear? Let me know, i’ll code or rather show your code for the same, that will help more.