Assuming I have 30 random numbers inside my priority queue, how do I access only a specific number of largest values after I sort them. For example I need to print the top 10 largest numbers inside my priority queue
So you push all random numbers into the queue: ok. Then you access the top numbers, and while you go, remove them from list:
const int desired_numbers = 10;
for(int i=0; i<desired_numbers; i++)
{
int t = mypq_decreasing.top();
mypq_decreasing.pop();
mylist.remove(t); //remove from original list
}
After this, both the queue and the list contain all random numbers, but ten (because after every access to top, you popped the top out of the queue and removed the element from list).