注册 登录
编程论坛 C++教室

初学队列

酷爱陈阳 发布于 2015-01-16 18:45, 463 次点击
#include <cstdio>
#include <iostream>
#include <queue>
using namespace std;
queue<int>q;
int main()
{
    int n;
    scanf("%d",&n);
    int i;
    for(i=1;i<=n;i++)
        q.push(i);
    while(!q.empty())
    {
        printf("%d ",q.front());
        q.pop();
        q.push(q.front());
        q.pop();
    }
    return 0;
}



为什么在输出正确答案后程序就停止正确运行了
1 回复
#2
天使梦魔2015-01-18 10:44
q.push(q.front());
什么意思,把队列的头加入队列?你想干什么,没清楚逻辑
1