typedef int Elemtype
typedef struct
{
Elemtype data[MAXSIZE];
int front;
int rear;
}SqQueue;
Status InitQueue(SqQueue *Q)
{
Q->front=0;
Q->rear=0;
return OK;
}
int QueueLength(SqQueue Q)
{
return (Q.rear-Q.front+MAXSIZE)%MAXSIZE;
}
Status EnQueue(SqQueue *Q,Elemtype e)
{
if((Q->rear+1)%MAXSIZE==Q->front) return ERROR;//队列满的判断
Q->data[Q->rear]=e;
Q->rear=(Q->rear+1)%MAXSIZE;
return OK;
}
Status DeQueue(SqQueue *Q,Elemtype &e)
{
if(Q->front==Q->rear) return ERROR;//队列空的判断
e=Q->data[Q->front];
Q->front=(Q->front+1)%MAXSIZE;
return OK;
}
循环队列的相关操作(顺序结构)
最新推荐文章于 2022-04-15 15:51:12 发布