间隔输出队列

初始化队列后,输出对头元素,然后将第二个元素放在队尾,依次类推,直到队列元素全部输出

利用C++自带的队列头文件

源代码如下:

#include<cstdio>
#include<queue>
using namespace std;
queue<int>q;
int main()
{
    
    int n;
    int i;
    scanf("%d",&n);
    for(i=0;i<n;i++)
        q.push(i+1);
    while(!q.empty())
    {
        printf("%d  ",q.front());
        q.pop();
        if(!q.empty())
        {q.push(q.front());
        q.pop();
        }
    }
    return 0;
}
选择了远方,便只顾风雨兼程
原文地址:https://www.cnblogs.com/ly-rabbit-wust/p/5575142.html