6
std::priority_queue<some_type, std::vector<some_type>, some_comparator> A;
std::priority_queue<some_type, std::vector<some_type>, some_comparator> B;

How can I merge these priority queues A and B based on same comparator. I tried to find builtin function but could not find any.

Utkrist Adhikari
  • 1,032
  • 2
  • 13
  • 33

1 Answers1

6

The simplest way is to simply move objects from one queue to another:

while(!B.empty()) {
    A.push(B.top());
    B.pop();
}

There might exist a more efficient method, though.

zch
  • 14,551
  • 2
  • 40
  • 49