版权声明:转载请注明出处 https://blog.csdn.net/nanhuaibeian/article/details/81916601
对仅含有队尾的循环队列进行初始化、入队、出队操作
define QUEUE 40 /队列的最大长度/
struct Queue {
int queue[QUEUE];
int Rear; // Rear记录队列尾
};
/初始化操作/
void InitQueue(Queue *Q)
{
Q->rear=0;
count=0;/计数器count用来记录队列中节点的个数/
}
/入队操作/
int EnQueue(Queue *Q,QueueElementType x)
{
if(count==QUEUE)/队列上溢/
{return FALSE;}
count++;
rear = (rear+1)%QUEUE;
Q->queue[rear]=x;
return TRUE;
}
/出队操作/
int DelQueue(Queue *Q,QueueElementType *x)
{
int temp;
if(count==0)/队空/
{return FALSE;}
temp =(rear-count+QUEUE)%QUEUE +1;/计算出队的下标指针/
(*x)=Q->queue[temp];
count–;
return TRUE;
}