I have a vector that defines the order of elements (0..N-1), for example. {5, 0, 4, 3, 2, 1, 7, 6} .
I need to sort the subsets of this vector. So, for {0, 1, 2, 5} I have to get {5, 0, 2, 1} .
I tested the following solutions:
- Create a set of elements in a subset, then clear the subset, go through the ordering vector, adding only the elements to the set.
- Create a new sorted vector by going through the ordering vector, adding only the elements found in a subset of
std::lower_bound .
The second solution seems much faster, although it requires a subset to sort it. Are there any better solutions? I am using C ++ / STL / Qt, but the problem is probably language independent.
source share