【发布时间】:2016-04-30 04:41:35
【问题描述】:
我正在学习关于队列的课程,但对于可能不是用户输入的项目(例如文件。我尝试运行一个 for 循环,以便将某些项目排入队列,例如仅将偶数整数(来自列表 1-10)放入队列:
for(int i = 1; i <= 10; i++)
{
if(i % 2 == 0)
while(intQueue.enqueue(i))
cout << i << " has been added to the queue . . .\n";
}
但由于某种原因,我只会在重复时将第一项添加到队列中:
2 has been added to the queue . . .
2 has been added to the queue . . .
2 has been added to the queue . . .
2 has been added to the queue . . .
2 has been added to the queue . . .
我想知道是不是我做的不对,或者是否有其他方法可以将某些项目排入队列。非常感谢任何帮助或提示。
【问题讨论】:
-
删除
while()