#include<iostream>
#define MAXQSIZE 100
using namespace std;
typedef int QElemType;
typedef struct
{
QElemType *base;
int front;
int rear;
}SqQueue;
void InitQueue(SqQueue &Q)//循环队列的初始化
{
Q.base = new QElemType[MAXQSIZE];
if(!Q.base)exit(OVERFLOW);
Q.front = Q.rear = 0;
}
int QueueLenght(SqQueue Q)//求循环队列的长度
{
return (Q.rear - Q.front + MAXQSIZE)%MAXQSIZE;
}
void EnQueue(SqQueue &Q,QElemType &e)//循环队列的入队
{
if((Q.rear + 1) % MAXQSIZE == Q.front) return;
Q.base[Q.rear] = e;
Q.rear = (Q.rear + 1) % MAXQSIZE;
}
void DeQueue(SqQueue &Q,QElemType &e)//循环队列的出队
{
if(Q.front == Q.rear)return ;
e = Q.base[Q.front];
Q.front = (Q.front + 1) % MAXQSIZE;
}
QElemType GetHead(SqQueue Q)//取循环队列的头元素
{
if(Q.front != Q.rear)return Q.base[Q.front];
}
原文:https://www.cnblogs.com/hhjjy/p/13996357.html