您的位置:首页 > 其它

循环队列的相关操作(顺序结构)

2017-03-24 17:58 405 查看
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;
}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: