//Author:PanDaoxi
#include <iostream>
using namespace std;
// 创建队列
const int MaxSize=101;
int q[MaxSize],front=0,rear=0;
void push(int value){ // 入队操作
if(rear<MaxSize) q[rear++]=value;
}
int pop(){ // 出队操作
if(front!=rear) return q[front++];
}
int main(){
int n,temp;
cin>>n;
for(int i=1;i<=n;i++){
push(i);
}
for(int i=1;i<=n;i++){
cout<<pop()<<" ";
push(pop());
}
return 0;
}
或是这样:
//Author:PanDaoxi
#include <iostream>
using namespace std;
int main(){
int n,a[10000],front=0,rear=0;
cin>>n;
for(int i=0;i<n;i++){
a[i]=i+1;
}
rear=n;
while(front<rear){
cout<<a[front++]<<" ";
a[rear++]=a[front++];
}
return 0;
}