**循环队列**
队首Q->Front=(Q->Front+1)%Q->MaxSize;
队尾Q->Rear=(Q->Front+Q->Count)%Q->MaxSize;
通用的计算队列长度公式:(rear-front+QueueSize)%QueueSize;
队列满的条件是:(rear+1)%QueueSize==front;
队列空的判断:(Q->front==Q->rear);
bool AddQ( Queue Q, ElementType X )
{
if(Q->MaxSize==Q->Count)
{
printf("Queue Full\n");
return false;
}
Q->Data[(Q->Front+Q->Count)%Q->MaxSize]=X;//Q->Rear=(Q->Front+Q->Count)%Q->MaxSize;
Q->Count++;
}
ElementType DeleteQ( Queue Q )
{
int e;
if(Q->Count==0)
{
printf("Queue Empty\n");
return ERROR;
}
e=Q->Data[Q->Front];
Q->Front=(Q->Front+1)%Q->MaxSize;
Q->Count--;
return e;
}