#include
using namespace std;
#include
template <class T, int MaxSize >
class SeqQueue
{
T data[MaxSize];
int front, rear;
public:
SeqQueue();
void EnQueue(T x);
T DeQueue();
T GetQueue();
bool Empty();
};
template <class T, int MaxSize>
SeqQueue<T,MaxSize>::SeqQueue()
{
front=rear=0;
}
template <class T, int MaxSize>
void SeqQueue<T,MaxSize>::EnQueue(T x)
{ if ((rear+1) % MaxSize front)
{ cerr<<“上溢”; exit(1);}
rear=(rear+1) % MaxSize;
data[rear]=x;
}
template <class T,int MaxSize>
T SeqQueue<T,MaxSize>::DeQueue()
{
if (rearfront)
{ cerr<<“下溢”; exit(1);}
front=(front+1) % MaxSize;
return data[front];
}
template <class T,int MaxSize>
bool SeqQueue<T,MaxSize>::Empty()
{
return rear==front;
}
void Number(int n)
{ SeqQueue<int,100> EnQueue;
for (int i=1;i<=n;i++)
EnQueue.EnQueue(i);
while (!EnQueue.Empty())
{ int x=EnQueue.DeQueue( ); cout<<x<<" ";
if (!EnQueue.Empty())
{ int y=EnQueue.DeQueue( );
EnQueue.EnQueue(y); }
}
}
int main()
{
int n;
cout<<“请输入有多少人需要列队:”;
cin>>n;
Number(n);
return 0;
}