0

たとえば、priority_queue<int> s;いくつかの要素を含む which があります。次のコードの正しい形式は次のとおりです。

while (!s.empty()) {
    int t=s.pop();// this does not retrieve the value from the queue
    cout<<t<<endl;
}
4

1 に答える 1

7

popドキュメントを参照すると、戻り値がないことがわかります。これにはさまざまな理由がありますが、それは別のトピックです。

適切な形式は次のとおりです。

while (!s.empty())
{
    int t = s.top();
    s.pop();

    cout << t << endl;
}

または:

for (; !s.empty(); s.pop())
{
    cout << s.top(); << endl;
}
于 2010-07-15T20:29:09.950 に答える