I need to implement a priority queue for a project, but the STL\'s priority_queue
is not indicated since we need to iterate over all elements and remove them random
You should be able to implement your own priority queue using std::vector
, std::make_heap
, std::push_heap
, and std::pop_heap
. Isn't this how std::priority_queue
is implemented? You'll just need to call std::make_heap
again to fix the data structure when you remove a random element.
Do you need to iterate over the elements in order? There's a std::sort_heap
algorithm to order the underlying std::vector
.