たとえば、priority_queue<int> s;
いくつかの要素を含む which があります。次のコードの正しい形式は次のとおりです。
while (!s.empty()) {
int t=s.pop();// this does not retrieve the value from the queue
cout<<t<<endl;
}
たとえば、priority_queue<int> s;
いくつかの要素を含む which があります。次のコードの正しい形式は次のとおりです。
while (!s.empty()) {
int t=s.pop();// this does not retrieve the value from the queue
cout<<t<<endl;
}
pop
ドキュメントを参照すると、戻り値がないことがわかります。これにはさまざまな理由がありますが、それは別のトピックです。
適切な形式は次のとおりです。
while (!s.empty())
{
int t = s.top();
s.pop();
cout << t << endl;
}
または:
for (; !s.empty(); s.pop())
{
cout << s.top(); << endl;
}