huoche.c
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include "huoche.h"
#define MAX 10001000
LLIST *p_checi=NULL;
char from[40];
char arrive[40];
int between;
int between_;
char wx[40];
char er[40];
char mingzi[40];
int checi_cmp(void *key, void *record)
{
char *checi_name=key;
struct checi *p=record;
return strcmp(checi_name,p->checi_name);
}
int zhanming_cmp(void *key, void *record)
{
char *zhanming=key;
struct chezhan *p=record;
return strcmp(zhanming,p->zhanming);
}
void create_checi_list()
{
p_checi=llist_create(sizeof(struct checi));
}
void add_checi()
{
struct checi cc;
char checi_name[10];
printf("==============\n");
printf("请输入车次:");
scanf("%s", checi_name);
strcpy(cc.checi_name, checi_name);
cc.p_chezhan=llist_create(sizeof(struct chezhan));
while(1)
{
struct chezhan cz;
printf("请输入车站名称(输入-1结束):");
char zm[40];
scanf("%s",zm);
if(strcmp(zm, "-1")==0)
{
break;
}
strcpy(cz.zhanming,zm);
printf("请输入本站价格:");
scanf("%d", &cz.jiage);
printf("请输入入站时间:");
scanf("%d %d %d", &cz.h.hour, &cz.h.minute, &cz.h.day);
printf("请输入出站时间:");
scanf("%d %d %d", &cz.x.hour, &cz.x.minute, &cz.x.day);
llist_insert(cc.p_chezhan,&cz,2);
}
llist_insert(p_checi,&cc,2);
}
void delete()
{
char checi_name[10];
char zhanming[40];
struct checi *train;
struct chezhan *station;
int x;
printf("==============\n");
printf("删除车次输入1\n");
printf("删除车站输入2\n");
scanf("%d", &x);
if(x==1)
{
printf("------------------------------------------------------\n");
printf("请输入需要删除的车次:");
scanf("%s", checi_name);
printf("------------------------------------------------------\n");
train=llist_find(p_checi,checi_name,checi_cmp);
if(train!=NULL)
{
llist_delete(p_checi,checi_name,checi_cmp);
printf("删除成功!\n");
printf("------------------------------------------------------\n");
}
else
{
printf("!!!未找到该车次!!!\n");
}
}
else
{
printf("------------------------------------------------------\n");
struct checi *train;
printf("请输入需要删除的车次:");
scanf("%s", checi_name);
printf("------------------------------------------------------\n");
train=llist_find(p_checi,checi_name,checi_cmp);
if(train!=NULL)
{
printf("请输入需要删除的车站:");
scanf("%s", zhanming);
printf("------------------------------------------------------\n");
station=llist_find(train->p_chezhan,zhanming,zhanming_cmp);
if(station!=NULL)
{
llist_delete(train->p_chezhan,zhanming,zhanming_cmp);
printf("删除成功!\n");
printf("------------------------------------------------------\n&#