Merge two priority queues

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 combine these priority queues A and B based on the same comparator. I tried to find a built-in function, but could not find it.

+6
source share
1 answer

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

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

However, a more efficient method may exist.

+5
source

Source: https://habr.com/ru/post/949822/


All Articles