该楼层疑似违规已被系统折叠 隐藏此楼查看此楼
void main()
{struct LinkQueue q;
Data e;
FILE *fp;
int flag=1,k,i,m;
char c,*menu[]={
"\n1:Creat a Queue and enter the data\n",
"2:Insert a data\n",
"3:Delete a data\n",
"4:Print a List\n",
"5:Save into file\n",
"6:The length of the list\n",
"7:Clear the Queue\n",
"8:The Anv\n",
"9:Destory the Queue\n",
"10:The MAX\n",
"0:Exit\n",
"Select[0-10]:"
};
while(flag){
for(k=0;k<=11;k++)
printf("%s",menu[k]);
scanf("%d",&k);
switch(k){
case 1:
New(&q); break;
case 2:
printf("Where do you want to put the data:\n");
scanf("%d",&m);
printf("Input the data you want to insert:\nNAME:\n");
scanf("%s",&e.name);
printf("XUEHAO:\n");
scanf("%d",&e.grade);
Insert(&q,m,e); break;
case 3:
printf("Input the num of the data you want to delet:\n");
scanf("%d",&i);
Del(&q,i); break;
case 4:
Out(&q); break;
case 5:if((fp=fopen("what.txt","wb"))==NULL){
fprintf(stderr,"error:can't creat file what!!!\n");
return;
}
fwrite(&q,sizeof(struct QNode),1,fp);
Save(&q,fp);
fclose(fp);break;
case 6:printf("The length of the list is %d\n",Length(&q));break;
case 7:Clear(&q);break;
case 8:printf("The anverage of the list is %d\n",Anv(&q));break;
case 9:Destory(&q);break;
case 10:printf("The Max data of the list is %d\n",Max(&q));break;
case 0:printf("Save your change??(y/n)");
scanf("%c%*c",&c);
c=='y'||c=='Y'?(c=1):(c=0);
if©{
if((fp=fopen("what.txt","wb"))==NULL) {
fprintf(stderr,"error:can't creat file what!!\n");
return;
}
rewind(fp);
fwrite(&q,sizeof(struct QNode),1,fp);
Save(&q,fp);
fclose(fp);
}
flag=0;
break;
default:
fprintf(stderr,"Select error!!!!!!!\n");
}
}
}