#include<stdio.h>
#include<stdlib.h>
#define QueueSize 100
typedef char DataType;
typedef struct {
DataType data[QueueSize];
int front, rear;
}CirQueue;
//置空队列
void InitQueue(CirQueue *Q) {
Q->front = Q->rear;
}
//判空队列
int QueueEmpty(CirQueue* Q) {
return Q->front == Q->rear;
}
//判队满
int QueueFull(CirQueue* Q) {
return (Q->rear+1)% QueueSize == Q->front;
}
//入队列
void enQueue(CirQueue* Q,DataType x) {
if (QueueFull( Q)) {
printf("queue overflow");
}
else {
Q->data[Q->rear] = x;
Q->rear = (Q->rear + 1) % QueueSize;
}
}
//取对头元素
DataType GetFront(CirQueue* Q) {
if (QueueEmpty(Q)) {
printf("queue empty");
exit(0);
}
else
{
return Q->data[Q->front];
}
}
//出队列
DataType DeQueue(CirQueue* Q) {
DataType x;
if (QueueEmpty(Q)) {
printf("queue empty");
exit(0);
}
else {
x= Q->data[Q->front];
Q->front = (Q->front + 1) % QueueSize;
return x;
}
}