#include <>#include <>#include <>//#include <>#define MAXSIZE 3typedef struct wat_ros{ char name[10]; int req_amt; struct wat_ros *next;}qnode,*qptr;typedef struct pqueue{ qptr front; qptr rear;}linkqueue;typedef struct ord_ros{ char name[10]; int ord_amt; int grade; struct ord_ros *next;}linklist;struct airline{ char ter_name[10]; /* 站点名 */ char air_num[10]; /* 航班号 */ char plane_num[10]; /* 飞机号 */ char date[7]; /* 飞行日期 */ int tkt_amt; /* 乘员定额 */ int tkt_sur; /* 余票量 */ linklist *order; linkqueue wait;}lineinfo;struct airline *start;struct airline air[MAXSIZE]={ {"beijing", "1", "B8571", "SUN", 3, 1}, {"shanghai","2","S1002","MON",2,5}, {"london","3","L1003","FRI",1,3}};;void display(struct airline *info){ printf("%8s\t%3s\t%s\t%4s\t\%d\t\%d\t\n",info->ter_name,info->air_num,info->plane_num,info->date,info->tkt_amt,info->tkt_sur);} /* 浏览航线信息函数 */void list(){ struct airline *info; int i = 0; info = start; printf("终点站名\t航班号\t飞机号\t飞行日期" "乘员定额" "余票量\n"); while(i < MAXSIZE){ display(info); info++; i++; } printf("\n\n");}void search(){ struct airline *info,*find(); char name[10]; int i=0; info=start; printf("请输入终点站名:"); scanf("%s",name); while(iter_name)) break;info++;i++;}if(i>=MAXSIZE)printf("对不起,该航线未找到!\n");else{printf("终点站名\t航班号\t飞机号\t飞行日期\t乘员定额\t余票量\n");display(info);}}struct airline *find(){ struct airline *info; char number[10]; int i=0; info=start; printf("请输入航班号:"); scanf("%s",number); while(iair_num)) return info; info++; i++; } printf("对不起,该航线末找到!\n"); return NULL;} /* 浏览已订票客户信息 */void prtlink(){ linklist *p; struct airline *info; info=find(); p=info->order; if(p!=NULL){ printf("客户姓名 订票数额 舱位等级\n"); while(p){ printf("%s\t\t%d\t%d\n",p->name,p->ord_amt,p->grade); p=p->next; } } else printf("该航线没有客户信息!!\n");}linklist *insertlink(linklist *head,int amount,char name[],int grade){ linklist *p1,*new1;p1=head;new1=(linklist *)malloc(sizeof(linklist));if(!new1) {printf("\nOut of memory!!\n");return NULL;}strcpy(new1->name,name);new1->ord_amt=amount;new1->grade=grade;new1->next=NULL;if(head==NULL){head=new1;new1->next=NULL;}elsehead=new1;new1->next=p1;return head;}linkqueue appendqueue(linkqueue q,char name[],int amount){ qptr new1;new1=(qptr)malloc(sizeof(qnode));strcpy(new1->name,name);new1->req_amt=amount;new1->next=NULL;if();>next=new1;;return q;}void order(){ struct airline *info;int amount,grade;char name[10];info=start;if(!(info=find())) return;printf("请输入你订票所需要的数量:");scanf("%d",&amount);if(amount>info->tkt_amt){ printf("\n对不起,您输入的票的数量已经超过乘员定额!");return;}if(amount<=info->tkt_sur){int i;printf("请输入您的姓名(订票客户):");scanf("%s",name);printf("请输入%s票的舱位等级:",name);scanf("%d",&grade);info->order=insertlink(info->order,amount,name,grade);for(i=0;itkt_amt-info->tkt_sur+i+1);info->tkt_sur-=amount;printf("\n祝您乘坐愉快!\n");}else{ char r; printf("\n已经没有更多的票,您需要排队等候吗?(Y/N)");//r=getch();//printf("%c",r); scanf ( "回车继续等待%c", &r );if(r=='Y'||r=='y'){ printf("\n请输入您的姓名(排队订票客户):");scanf("%s",name);info->wait=appendqueue(info->wait,name,amount);printf("\n注册成功!\n");}else printf("\n欢迎您下次再次订购!\n");}}void return_tkt(){ struct airline *info;qnode *t,*back,*f,*r;int grade;linklist *p1,*p2,*head;char cusname[10];if(!(info=find())) return;head=info->order;p1=head;printf("请输入你的姓名(退票客户):");scanf("%s",cusname);while(p1!=NULL) {if(!strcmp(cusname,p1->name)) break;p2=p1;p1=p1->next;}if(p1==NULL){ printf("对不起,你没有订过票!\n");return;}else{if(p1==head) head=p1->next;else p2->next=p1->next;info->tkt_sur+=p1->ord_amt;grade=p1->grade;printf("%s成功退票!\n",p1->name);free(p1);}info->order=head;f=(info->wait).front;r=(info->wait).rear;t=f;while(t){ if((info->tkt_sur = info->>req_amt)){int i;info->>next;printf("%s订票成功!\n",t->name);for(i=0;ireq_amt;i++)printf("%s的座位号是:%d\n",t->name,(info->tkt_sur)-i);info->tkt_sur-=t->req_amt;info->order=insertlink(info->order,t->req_amt,t->name,grade);free(t);break;}back=t;t=t->next;if((info->tkt_sur)>=(t->req_amt)&&t!=NULL){ int i;back->next=t->next;printf("%s订票成功!\n",t->name);for(i=0;ireq_amt;i++)printf("<%s>'s seat number is:%d\n",t->name,(info->tkt_sur)-i);info->tkt_sur-=t->req_amt;info->order=insertlink(info->order,t->req_amt,t->name,grade);free(t);break;}if(f==r) break;}}void sort_tkt(){int j;struct airline t,*info,*p,*q;p=info=air;for(p=info;(p+1)->tkt_sur;p++)for(q=p+1;q->tkt_sur;q++){if(p->tkt_surtkt_sur){t=*p;*p=*q;*q=t;}}printf("终点站名\t航班号\t飞机号\t飞行日期\t乘员定额\t余票量\n");for(j=0;j 7); return c;}int main(){ start = air; for(;;) { switch(menu_select()) { case 1:list();break; case 2:prtlink();break; case 3:search();break; case 4:order();break; case 5:return_tkt();break; case 6:sort_tkt();break; case 0:printf("\n欢迎使用本系统,再见!\n");exit(0); } printf("\nPress any key to continue!\n"); getchar(); } return 0;}