我正在尝试打印下面的队列。我尝试过创建一个临时队列,并将其写入,然后将其写回。
但它不起作用。
或者我错过了什么?
for(int i = 1; i<myQueue.size(); i++)
{
queue<int> tempQueue;
cout << myQueue.front() << endl;
MytempQueue.push(myQueue.front());
myQueue.pop();
myQueue.push(myTempQueue.back());
}我的队列是queue<int> myQueue;
本质上,我想打印这个队列而不是清空它...但我被困在这里了。
发布于 2022-02-28 07:13:46
(int i= 1;i的
循环应以0开头,或检查条件应为<=
queue<int> myQueue;
myQueue.push(1);
myQueue.push(2);
myQueue.push(3);
myQueue.push(4);
myQueue.push(5);
for (size_t i = 0; i < myQueue.size(); i++)
{
cout << myQueue.front() << endl;
myQueue.push(myQueue.front());
myQueue.pop();
}https://stackoverflow.com/questions/22280318
复制相似问题