I have a question that could seem very basic, but it is in a context where \"every CPU tick counts\" (this is a part of a larger algorithm that will be used on supercomputers).<
Use std::vector
and std::sort
. That should provided the fastest sort method. To Find the original index create a struct.
struct A {
int num;
int index;
}
Then make your own compare Predicate for sort that compares the num in the struct.
struct Predicate {
bool operator()(const A first, const A second) {
return first.num < second.num;
}
}
std::sort(vec.begin(), vec.end(), Predicate())