国家安全手抄报
⽕车票订票系统(链表结构化设计)train.h⽂件
#define  _CRT_SECURE_NO_WARNINGS
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
struct train {//车次的属性
int id;
char name[50];
int remainTickets;
};
struct node {//普通节点的属性
struct node *next;
struct train * train_inform;
};
struct head {//头节点属性
struct node * nd;
int fg;
};
struct tail {//尾节点属性
struct node * nd;
int fg;
};
struct list{//链表的属性
struct head * listhead;
欧阳娜娜 刘昊然int len;
};
struct list * initList();
struct list * createList(struct list * l);
struct node * searchTrain(struct list * l,int id);
int printNode(struct node * train);
int bookTrain(struct list * l,int id);
int returnTrain(struct list * l,int id);
int menu(struct list * l);
int usage(void);
/
train.c⽂件
#include "train.h"
int main()
{
usage();
return 0;
}
struct list * initList(){
三星 烧屏struct list * l;
l = (struct list *)malloc(sizeof(struct list));
l->listhead = (struct head *)malloc(sizeof(struct head));
l->listhead->nd = (struct node *)malloc(sizeof(struct node));
l->listhead->nd->train_inform = (struct train *)malloc(sizeof(struct train)); l->listhead->nd->next=NULL;
l->len=0;
return l;
}
struct list * createList(struct list * l){
int id;
char name[50];
int remainTickets;
struct node * p, * last;
last=l->listhead->nd;
printf("依次输⼊:列车id号,名称,剩余票数(id==-1终⽌!)\n");
scanf("%d%s%d",&id,&name,&remainTickets);
while(id!=-1){
p=(struct node *)malloc(sizeof(struct node));
p->train_inform=(struct train *)malloc(sizeof(struct train));
p->train_inform->id=id;
strcpy(p->train_inform->name,name);
p->train_inform->remainTickets=remainTickets;
l->len++;
last->next=p;
last=p;
p->next=NULL;
scanf("%d%s%d",&id,&name,&remainTickets);
}
return l;
}
struct node * searchTrain(struct list * l,int id){//查询,返回节点信息
struct node * p;
p = l->listhead->nd;
while(p!=NULL){
if(p->train_inform->id==id){
break;
}
p=p->next;
}
return p;
}
int printNode(struct node * train){//打印节点信息
printf("列车id: %d\n",train->train_inform->id);
printf("列车名称:%s\n",train->train_inform->name);
printf("剩余票数:%d\n",train->train_inform->remainTickets);
return 0;
}
int bookTrain(struct list * l,int id){//订票
struct node * p;
p = l->listhead->nd;
while(p!=NULL){
if(p->train_inform->id==id){
p->train_inform->remainTickets--;
break;
}
p=p->next;
}
printNode(p);
return 0;
return 0;
}
int returnTrain(struct list * l,int id){//退票 struct node * p;
p = l->listhead->nd;
while(p!=NULL){
if(p->train_inform->id==id){
p->train_inform->remainTickets++;  break;
}
p=p->next;
}
printNode(p);
return 0;
}
int menu(struct list * l){//具体实现usage  int x,id;
int k=1;
struct node * p;
while(k){
printf("请输⼊序列号:");黄立行电影
scanf("%d",&x);
switch(x){
case 1:
printf("输⼊所要查询的列车的id号:");  scanf("%d",&id);
p = searchTrain(l,id);
printNode(p);
break;
case 2:
printf("输⼊所要订票的列车的id号:");  scanf("%d",&id);
bookTrain(l,id);
break;
case 3:
printf("输⼊所要订票的列车的id号:");  scanf("%d",&id);
bookTrain(l,id);
break;
case 4:k=0;break;
default:return 0;
}
}短头发怎么扎
return 0;
}
int usage(void){//打印提⽰界⾯
海绵宝宝歌词struct list * l;
l=initList();
printf("请输⼊列车原始信息!\n");
l = createList(l);
printf("请按提⽰输⼊完成操作!\n");
printf("1.查询车次信息\n");
printf("2.订票\n");
printf("3.退票\n");
printf("4.退出系统\n");
menu(l);
return 0;
}