The previous version of my function takes a priority queue(Deque) as input, and then a while loop handles the elements(a self-defined struct) inside. Now I want to support the random ordering to see if given a random sequence of input, how's the function perform. What's the best way to do this?
struct MyStruct {
int value;
// Other members...
struct Compare {
bool operator() (const std::shared_ptr<MyStruct>& a,
const std::shared_ptr<MyStruct>& b) const {
return a->value < b->value;
}
};
};
Function:
void process(const auto& std::unordered_set<std::shared_ptr<MyStruct>>& myStructSet) {
std::priority_queue<shared_ptr<MyStruct>, std::deque<shared_ptr<MyStruct>>,
Compare>
orderedStructs(myStructSet.begin(), myStructSet.end());
while (!orderedStructs.empty()) {
...
}
}
What I want is that if the program has been told to use random ordering, it should create a randomOrderedStructs instead, the only difference between the two versions should be the ordering(sequence) inside the deque.
Aucun commentaire:
Enregistrer un commentaire