有个设了队头,队尾的,你参考下,入队的时候队尾指针变,出队的时候队头指针变
int EnQueue(CirQueue *Q, DataType e)//入队
{
if (Q->quelen == QueueSize) //队满条件
{
printf("Queue is full! Cannot EnQueue.n");
return 0;
}
else
{
Q->data[Q->rear] = e;
Q->rear = (Q->rear + 1) % QueueSize;//实现循环
Q->length++;
return 1;
}
}
DataType DeQueue(CirQueue *Q)//出队
{
if (Q->length == 0) //队空
{
printf("Queue is empty! Cannot DeQueue.n");
return 0;
}
else
{
DataType ret = Q->data[Q->front];//记录出队元素的值
Q->front = (Q->front + 1) % QueueSize;//该语句用来实现循环
Q->length--;
return ret;//返回出队元素值
}
}