#include<stdlib.h>
#include<stdio.h>
#include<string.h> //引入头文件
#define MAXLEN 20 //宏定义
typedef struct{ //节点定义
char name[10];
int age;
}SD;
typedef struct{ //队列
SD sd[MAXLEN];
int head;
int tail;
}QueueType;
QueueType *Init(){ //初始化
QueueType *qt;
if(qt=(QueueType *)malloc(sizeof(QueueType))){
qt->head=0;
qt->tail=0;
return qt;
}else return NULL;
}
int IsEmpty(QueueType *qt){
if(qt->head==qt->tail)
return 1;
else return 0;
}
int IsFull(QueueType *qt){
if(qt->tail==MAXLEN)
return 1;
return 0;
}
void Clear(QueueType *qt){
qt->head=0;
qt->tail=0;
}
void Free(QueueType *qt){
if(qt!=NULL)
free(qt);
}
//入队
int Insert(QueueType *qt,SD sd){
if(qt->tail==MAXLEN)
{
printf("已满");
return 0;
}
qt->sd[qt->tail++]=sd;
return (1);
}
//出队
SD *Out(QueueType *qt){
if(qt->head==qt->tail)
{
printf(“已空”);
exit(0);
}
return &(qt->sd[qt->head++]);
}
void main(){
QueueType *qt;
SD sd1,*sd2;
qt=Init();
printf("入队:\n姓名 年龄\n");
do{
scanf("%s",&sd1.name);
if(strcmp(sd1.name,"0")==0)
break; //控制结束
else{
scanf("%d",&sd1.age);
Insert(qt,sd1);
}
}while(1);
printf("出栈:\n");
getchar();
do{
sd2=Out(qt);
printf("%s %d\n",sd2->name,sd2->age);
}while(1);
Free(qt);
}