0
votes

I have a question regarding the implementation of priority_queue container adaptor. Now, I know it internally uses the push_heap, pop_heap functions. This is my question:

make_heap turns a vector into a heap in O(n) time by utilizing the heapify algorithm. Is there a similar heapify operation for priority queues in C++ STL? The only possible way of populating a priority_queue that I know of is by manually adding elements. Is there a method for batch insert also in C++ STL for priority_queue. I couldn't find anything on the C++ reference page.

1
Just pass the vector to priority_queue's constructor. - T.C.
Thanks a lot. Yeah, should have figured this out on my own. - Manav Garg

1 Answers

0
votes

Why just don't use std::priority_queue ?

http://www.cplusplus.com/reference/queue/priority_queue/

It does all insert/delete operations automatically. So you don't need to worry about keeping your container in priority queue order.