队列应用

 

n个人站一圈,数 1 2 1 2,数到1的出来,数到2 的继续保持一个圈。

输入 1 2 3 4 5 6 7 8

输出 1 3 5 7 2 6 4 8

#include<iostream>
#include<queue>
using namespace std;
int main(){
    int n,flag=0;
    cin>>n;
    queue<int> qq;
    for(int i=1;i<=n;i++)
        qq.push(i);
    while(!qq.empty()){
            cout<<qq.front()<<" ";
            qq.pop();
            qq.push(qq.front());
            qq.pop();        
    }
    return 0;
} 

 

posted @ 2020-06-14 17:31  wsl96  阅读(105)  评论(0编辑  收藏  举报