How to merge two priority_queue?
c++, c++11
Solution
`priority_queue` is a container adapter, not a regular standard container. In particular, it does not offer the `begin()` and `end()` member functions. Therefore, you will have to pop the elements out of one queue and push them into the other:
while (!queue2.empty())
{
queue1.push(queue2.top());
queue2.pop();
}
Problem
I have two `priority_queue` with `float` like this: ``` std::priority_queue<float> queue1; std::priority_queue<float> queue2; ``` And I need to merge them. But STL `merge` algorithm do not allow working with the `priority_queue` directly: ``` merge( queue1.begin(), queue2.end(), queue2.begin(), queue2.end(), queue1 ); ``` Is there a way to merge `priority_queue` without using auxiliary data structures?