C++ sorting and keeping track of indexes

后端 未结 15 2292
甜味超标
甜味超标 2020-11-22 10:01

Using C++, and hopefully the standard library, I want to sort a sequence of samples in ascending order, but I also want to remember the original indexes of the new samples.<

15条回答
  •  予麋鹿
    予麋鹿 (楼主)
    2020-11-22 10:23

    Are the items in the vector unique? If so, copy the vector, sort one of the copies with STL Sort then you can find which index each item had in the original vector.

    If the vector is supposed to handle duplicate items, I think youre better of implementing your own sort routine.

提交回复
热议问题