队列操作、栈操作
作者:互联网
队列
队满条件:(Q.rear+1)%maxsize==Q.front
队空条件:Q.front==Q.rear
队中元素个数:(Q.rear-Q.front+maxsize)%maxsize
//判队空
int isEmpty(SqQueue Q)
{
if(Q.rear==Q.front) return 1;
else
return 0;
}
//入队
int EnQueue(SqQeue &Q,ElemType x)
{
if((Q.rear+1)%maxsize==Q.front)
return 0;
Q.data[rear]=x;
Q.rear=(Q.rear+1)%maxsize;
return 1;
}
//出队
int DeQueue(SqQueue &Q,ElemType &e)
{
if(Q.front==Q.rear) return 0;
e=Q.data[front];
Q.front=(Q.front+1)%maxsize;
return 1;
}
标签:return,队列,SqQueue,int,maxsize,front,操作,rear 来源: https://blog.csdn.net/lws24919/article/details/121734664