#include <iostream>
#include <stdio.h>
#include <stdlib.h>
#define maxsize 100
using namespace std;
typedef struct {
int data[maxsize];
int front,rear;
int tag;
}squeue;
bool desqueue(squeue &sq,int &x){
if(sq.front==sq.rear&&sq.tag==0) return false;
else{
x=sq.data[sq.front];
sq.front=(sq.front+1)%maxsize;
if(sq.rear==sq.front) sq.tag=0;
return true;
}
}
bool ensqueue(squeue &sq,int x){
if(sq.front==sq.rear&&sq.tag==1) return false;
else{
sq.data[sq.rear]=x;
sq.rear=(sq.rear+1)%maxsize;
if(sq.rear==sq.front) sq.tag=1;
return true;
}
}
int main(){
squeue sq;
sq.front=0;
sq.rear=0;
sq.tag=0;
int x;
ensqueue(sq,3);
x = desqueue(sq,x);
printf("%d",x);
return 0;
}
[数据结构][队列]循环队列中增设tag用来区分Q.rear==Q.front是队空还是队满
最新推荐文章于 2023-07-29 23:31:38 发布
![](https://img-home.csdnimg.cn/images/20240711042549.png)