#include<stdio.h>
#define MAXSIZE 8
#define ERROR 0
#define Status int
#define SUCESS 1
typedef struct Node{
int front,rear;
int data[MAXSIZE];
}*Queue;
void InitQueue(Queue &queue){
queue->front = 0;
queue->rear = 0;
}
Status isEmpty(Queue queue){
if(queue->front == queue->rear){
return 1;
}else{
return 0;
}
}
Status isFull(Queue queue){
if((queue->rear+1)%MAXSIZE == queue->front){
return 1;
}else{
return 0;
}
}
Status addElement(Queue &queue,int data){
if(isFull(queue)){
return ERROR;
}
queue->rear = (queue->rear+1)%MAXSIZE;
queue->data[queue->rear] = data;
return SUCESS;
}
Status getElement(Queue &queue,int &data){
if(isEmpty(queue)){
return ERROR;
}
queue->front = (queue->front+1)%MAXSIZE;
data = queue->data[queue->front];
return SUCESS;
}
int main(){
Queue queue;
InitQueue(queue);
addElement(queue,1);
addElement(queue,2);
addElement(queue,3);
int val1;
getElement(queue,val1);
printf("%d",val1);
getElement(queue,val1);
printf("%d",val1);
}
02-23
566
![](https://csdnimg.cn/release/blogv2/dist/pc/img/readCountWhite.png)
05-10
577
![](https://csdnimg.cn/release/blogv2/dist/pc/img/readCountWhite.png)
11-04
2154
![](https://csdnimg.cn/release/blogv2/dist/pc/img/readCountWhite.png)