For example we have priority_queue<int> s;
which contains some elements. What will be correct form of the following code:
while (!s.empty()) {
int t=s.pop();// this does not retrieve the value from the queue
cout<<t<<endl;
}
For example we have priority_queue<int> s;
which contains some elements. What will be correct form of the following code:
while (!s.empty()) {
int t=s.pop();// this does not retrieve the value from the queue
cout<<t<<endl;
}
Refer to your documentation and you'll see pop
has no return value. There are various reasons for this, but that's another topic.
The proper form is:
while (!s.empty())
{
int t = s.top();
s.pop();
cout << t << endl;
}
Or:
for (; !s.empty(); s.pop())
{
cout << s.top(); << endl;
}