#include <stdlib.h>
#define maxSize 5
//存放队列元素
int data[maxSize];
//对头指针
int front = 0;
//队尾指针
int rear = 0;
void enQueue(int e){
//牺牲一个存储单元判断队列为满
if((rear+1)%maxSize == front){
printf("queue is full \n");
}else{
data[rear] = e;
printf("%d is enQueue, saved in index %d \n",e,rear);
rear = (rear+1)%maxSize;
}
}
void deQueue(){
if(rear == front){
printf("queue is empty \n");
}else{
printf("%d deQueued, saved in index %d \n",data[front],front);
front = (front+1)%maxSize;
}
}
int main(){
enQueue(1);
enQueue(2);
enQueue(3);
enQueue(4);
enQueue(5);
deQueue();
deQueue();
deQueue();
deQueue();
deQueue();
return 0;
}