#include <iostream> using namespace std; #define MAX 100 typedef struct //循环体结构体 { int a[MAX]; int front; int rear; }CirQueue; void init(CirQueue &q) //初始化 front = rear = 0 { q.front = q.rear = 0; } void enqueue(CirQueue &q,int &x) //进队 a[rear] = x, rear = rear + 1 % max; { q.a[q.rear] = x; q.rear = (q.rear + 1) % MAX; } int dequeue(CirQueue &q) //出队 return a[front]; front = front + 1 % max; { int t = q.a[q.front]; q.front = (q.front + 1) % MAX; return t; } bool isEmpty(CirQueue &q) //队空 队首等于队尾 rear == front { return q.rear = q.front; } bool ifFull(CirQueue &q) //队满 队尾再进一个元素就变队头 即:front == (rear + 1) % MAX; { if((q.rear + 1)%MAX == q.front) return true; else return false; } int size(CirQueue &q) // 队大小 (rear - front + max) % max { return (q.rear - q.front + MAX) % MAX; } int main() { CirQueue q; init(q); int n; cin>>n; for(int i = 0;i<n;i++) enqueue(q, i); cout<<size(q)<<endl; for(int i = 0;i<n;i++) { cout<<q.front<<" "; dequeue(q); } cout<<endl<<size(q)<<endl; return 0; }