【正确答案】#define datatype char*
#define MAXSIZE 100 /*队列的最大容量*/
typedef struct
{datatype data[MAXSIZE]; /*队列的存储空间*/
int rear,front; /*队头队尾指针*/
}SEQQUEUE;
#include"stdlib.h"
#include"stdio.h"
#include"string.h"
#include"ctype.h"
#include"seqqueue.h"
SEQQUEUE*q;
void enter()
{ char s[64],*p;
int len;
while(1)
{printf("enter event/%d:",q->rear+1);
gets(s);
len=strlen(s);
if(len==0)break; /*没有事件*/
p=malloc(len+1);
if(!p)
{printf("memory not available.\n");
return;}
strcpy(p,s);
Add_Queue(q,p);
if((q->rear+1) /%MAXSIZE==q->front)
break;
}
}
void review()
{ int i=0,pos=q->front;
while(i!=QueueLength(q))
{pos=(pos+1)/%MAXSIZE;
printf("/%d./%s\n",i+1,q->data[pos]);
i++;
}
}
void delete()
{ char*p;
p=Del_Queue(q);
if(p)
{printf("/%s\n",p);
free(p);}
}
metin()
{ char ch;
Init_Queue(q); /*创建一个窄队列*/
do
{printf(" 1--Enter,2--List,3--Remove,4--quit: ");
oh=getchar();
getchar();
switch(ch)
{case '1':enter();break;
case '2':revieW()jbreak;
case '3':deiete();break;
}
}while(ch!='4');
}
程序运行实例如下:
1--Enter,2--List,3--Remove,4--Quit:1
enter event 1:Harry have a math at;8:00.
enter event 2:Harry will learn dancing at 1:00 pm.
enter event 3:Marry will watch TV at 6:30 pm.
enter event 4:<cr>
1--Enter,2--List,3--Remove,4--Quit:2
1.Harry have a math at8:00.
2.Harry will learn dancing at 1:00 pm.
3.Harry will watch TV at 6:30 pm.
1--Enter,2--List,3--Remove,4--Quit:3
Narry have a math at 8:00.
1--Enter,2--List,3--Remove,4-Quit:2
1.Harry will learn dancing at 1:00 pm.
2.Narry will watch TV at 6:30 pm.
1--Enter,2--List,3--Remove,4-Quit:4
【答案解析】