#include"stdio.h"
#include"stdlib.h"
typedef struct seq_queue
{
char *data;
int maxsize;
int front;
int rear;
}SEQ_QUEUE;
void init(SEQ_QUEUE *sq);
int en_queue(SEQ_QUEUE *sq,char data);
int isfull(SEQ_QUEUE sq);
int isdis_full(SEQ_QUEUE sq);
int dequeue(SEQ_QUEUE *sq,char data);
int main()
{
SEQ_QUEUE sq;
int flag;
char data;
char c;
init(&sq);
if(isfull(sq)==1){
for(data='a';data<'f';data++){
flag=en_queue(&sq,data);
printf("进队,%c\n",data);
}
}
if(isfull(sq)==1){
printf("入队成功个数为,%d\n",sq.rear);
}
else{
printf("入队失败");
}
while(isdis_full(sq)==1){
dequeue(&sq,c);
printf("出队,%c\n",c);
}
return 0;
}
void init(SEQ_QUEUE *sq){
sq->maxsize=8;
sq->data=(char *)malloc(sizeof(char)*(sq->maxsize));
sq->front=0;
sq->rear=0;
}
int en_queue(SEQ_QUEUE *sq,char data){
if(isfull(*sq)==1){
sq->data[sq->rear]=data;
sq->rear++;
return 1;
}
else{
return 0;
}
}
int isfull(SEQ_QUEUE sq){
if((sq.rear+1)%sq.maxsize==sq.front){
return 0;
}
else{
return 1;
}
}
int isdis_full(SEQ_QUEUE sq){
if(sq.rear==sq.front){
return 0;
}
else{
return 1;
}
}
int dequeue(SEQ_QUEUE *sq,char c){
if(isdis_full(*sq)==1){
sq->front++;
c=sq->data[sq->front];
return 1;
}
else{
return 0;
}
}