C++ STL priority queues

prem's Avatar, Join Date: Jan 2009
Newbie Member
i wanted to implement piority queues using c++ stl....

i want to extract both min and max elemnts (compute with the extracted value as well a s pop them out of queue)
for eg:
std:priority_queue<int> q;
i am able to pop the largest since front elemnet is largest...

well i want to pop the smallest elemnts as well..i also want the samallest and largest elemnt to be stored in a temp variable so as to compute sumthng else...

can u guide me on how do i do it here
sharmila's Avatar, Join Date: Mar 2006
I guess we can't delete the smaller value.. but while creating a priority_queue if we create using greater<int> then we can delete small value, but we can't delete higher value..

For the second question can we try somthing like this..
priority_queue<int> p(q);
int i, j;
i= p.top();
j = p.top();
so that q remains like that and p will be deleted by the end..

I am not sure how much it will work.. so thought to give my thoughts to start the discussion..

If it is not manditory to take a priority_queue we can take vector instead of that..