#include<malloc.h>
#include<stdio.h>
#include<stdlib.h>
#include<string.h>
#includ360问答e<conio.h>
#define LEN sizeof(struct tour_node)
struct tour_node
{ char jingdian层陈bianhao[4];
char jingdianm保照优讲到皮须须ingcheng[8];
float dianhua_tour;
float 现兰chengrenpiaojia_tour;
float ertongpiaojia_tour;
char lianxiren[8];
float shijian_t读副诗所our;
struct tour_node *next;
typedef struct tour_node journey;
int menu_sel();
journey *create兴走粉语致植术应断宽();
journey *add(journey *head);
journey *search(journey 干入守另*head);
journey *del(journey *head);
journey *update(journey *head);
void dis除怎市位结均play(journey *head);
journey *sort(journey *head);
void save(jou立月抗亲地卷东rney *head);
journey *load();
journey *head=NULL;
void input_x考粉尔德巴inxi(journey *j另缺ou);
main()
{ journey *head=NULL;
clrscr();
法始督真多大杀while(1)
{ switch(menu_sel())
{ case 1:head=create();break;
case 2:head=add(head);break;
case 3:head=search(head);break;
case 4:head=d跑电左系要移王把el(head);break;
case 5:display(head);船因成够曾查个密龙break;
case 6:head=sort(head);break;
case 7:head=update(head);break;
case 8:save(head)仍仍么接上设;break;
case 9:h高伤米ead=load();bre阳妈陈界没术京ak;
case 10:针死尔子祖是名朝游次exit(0);
int menu_sel()
{char *menu[]={"***************MENU**************",
"1.建立链表",
"2.添加记录",
"3.查询记录",
"4.删除记录",
"5.显示记录",
"6.根据成人票价排序",
"7.按成人票价显示",
"8.保存记录",
"9.导入记录",
"10.退出"
int c,i;
clrscr();
gotoxy(1,1);
textcolor(15);
textbackground(1);
gotoxy(10,2);
for(i=1;i<=41;i++)
putch('-');
for(i=3;i<14;i++)
{ gotoxy(10,i);putch('|');
gotoxy(50,i);putch('|');
gotoxy(10,14);
for(i=1;i<=41;i++)
putch('-');
window(11,3,49,13);
clrscr();
for(i=0;i<11;i++)
{ gotoxy(5,i+1);
cprintf("%s",menu[i]);
textbackground(0);
window(1,1,80,25);
gotoxy(10,14);
do{ printf("\n\tEnter you choice(0--10):");
scanf("%d",&c);
}while(c<1||c>10);
return c;
void input_xinxi(journey *jou)
{printf("请输入景点名称: ");
scanf("%s",jou->jingdianmingcheng);
printf("请输入电话: ");
scanf("%f",&jou->dianhua_tour);
printf("请输入成人票价: ");
scanf("%f",&jou->chengrenpiaojia_tour);
ptintf("请输入儿童票价: ");
scanf("%f",&jou->ertongpiaojia_tour);
printf("请输入联系人: ");
scanf("%s",jou->lianxiren);
printf("请输入时间: ");
scanf("%f",&jou->shijian_tour);
journey *create()
{ journey *head=NULL,*jou;
while(1)
{ clrscr();
jou=(journey *)malloc(sizeof(journey));
if(!jou)
{printf("\nout of memory");
return NULL;
printf("\nplease input jingdianbianhao.(jingdianbianhao.='0',exit.):");
scanf("%s",jou->jingdianbianhao);
if(strcmp(jou->jingdianbianhao,"0")==0)break;
input_xinxi(jou);
jou->next=head;
head=jou;
return(head);
journey *add(journey *head)
{ journey *p0,*p1,*p2,*jou;
int i,j,flag;
clrscr();
while(1)
{ flag=0;
p2=jou=(journey *)malloc(LEN);
printf("\n输入信息!");
printf("\nplease input jingdianbianhao.(jingdianbianhao.='0',exit.): ");
scanf("%s",jou->jingdianbianhao);
if(!strcmp(jou->jingdianbianhao,"0"))
break;
else
{ p2=head;
while(p2!=NULL)
{ if(strcmp(jou->jingdianbianhao,p2->jingdianbianhao)!=0)
p2=p2->next;
else
{ printf("请重新输入!\n");
flag=1;
break;
if(flag)
continue;
else
input_xinxi(jou);
clrscr();
p1=head;
p0=jou;
if(head==NULL)
{ head=p0;
p0->next=NULL;}
else
{while(p1->next!=NULL)
p1=p1->next;
p1->next=p0;
p0->next=NULL;
printf("\n---have inserted journey----\n");
printf("---别忘记存盘---\n");
printf("press any key to contiune.....\n");
getch();
return(head);
journey *search(journey *head)
{ journey *p;
char s[8];
clrscr();
printf("\nplease input jingdianmingcheng to search:\n");
scanf("%s",s);
p=head;
while(strcmp(p->jingdianmingcheng,s)&&p!=NULL)
p=p->next;
if(p==NULL)
printf("\ncan find the journey who named %s\n",s);
else
{ printf("-------------------------------------------------------------------\n");
printf("|景点编号\t|景点名称\t|电话\t|成人票价\t|儿童票价\t|联系人\t|时间\t|\n");
printf("-------------------------------------------------------------------\n");
printf("|%s\t|%s\t|%f\t|%f\t|%f\t|%s\t|%f\t|\n",p->jingdianbianhao,p->jingdianmingcheng,p->dianhua_tour,p->chengrenpiaojia_tour,p->ertongpiaojia_tour,p->lianxiren,p->shijian_tour);
printf("-------------------------------------------------------------------\n");
printf("********************************end*******************************\n");
return(head); }
journey *del(journey *head)
{ journey *p1,*p2;
char jingdianmingcheng[8];
clrscr();
printf("\nplease input jingdianmingcheng.(jingdianmingcheng='0',exit.):");
scanf("%s",jingdianmingcheng);
while(strcmp(jingdianmingcheng,"0")!=0)
{if(head==NULL)
printf("\n没有信息");
return(head);
p1=head;
while((strcmp(jingdianmingcheng,p1->jingdianmingcheng)!=0)&&(p1->next!=NULL))
{ p2=p1;
p1=p1->next;
if(strcmp(jingdianmingcheng,p1->jingdianmingcheng)==0)
{ if(p1==head)
{ head=p1->next;
free(p1);
else
{ p2->next=p1->next;
free(p1);
printf("删除:%s",jingdianmingcheng);
else
printf("没有信息(景点名称: %s) !\n",jingdianmingcheng);
printf("press any key to contiune.....\n");
getch();
clrscr();
printf("\n请输入景点名称: ");
scanf("%s",jingdianmingcheng);
void display(journey *head)
{ journey *jou;
int count=0;
clrscr();
if(head==NULL)
printf("\n没有信息");
else
{ printf("-------------------------------------------------------------------\n");
printf("|景点编号\t|景点名称\t|电话\t|成人票价\t|儿童票价\t|联系人\t|时间\t|\n");
printf("-------------------------------------------------------------------\n");
jou=head;
while(jou!=NULL)
{ count++;
printf("|%s\t|%s\t|%f\t|%f\t|%f\t|%s\t|%f\t|\n",jou->jingdianbianhao,jou->jingdianmingcheng,jou->dianhua_tour,jou->chengrenpiaojia_tour,jou->ertongpiaojia_tour,jou->lianxiren,jou->shijian_tour);
printf("-------------------------------------------------------------------\n");
jou=jou->next;
printf("journey's number=%d\n",count);
printf("press any key to contiune.....\n");
getch();
journey *sort(journey *head)
{ journey *p,*tail,*q,*r;
clrscr();
tail=head;
while(tail->next!=NULL)
{ p=tail->next;
if(p->chengrenpiaojia_tour<head->chengrenpiaojia_tour)
{ tail->next=p->next;
p->next=head;
head=p;
else
{ q=head;
r=q->next;
while(p->chengrenpiaojia_tour>r->chengrenpiaojia_tour)
{ q=r;
r=q->next;
if(p==r)
tail=p;
else
{ tail->next=p->next;
p->next=r;
q->next=p;
printf("sorting......");
printf("press any key to contiune.....\n");
getch();
return(head);
journey *update(journey *head)
{ float cpj;
journey *jou;
clrscr();
printf("\nplease input chengrenpiaojia: ");
scanf("%f",&cpj);
jou=head;
if(jou->chengrenpiaojia_tour<cpj)
{ printf("-------------------------------------------------------------------\n");
printf("|景点编号\t|景点名称\t|电话\t|成人票价\t|儿童票价\t|联系人\t|时间\t|\n");
printf("-------------------------------------------------------------------\n");
printf("|%s\t|%s\t|%f\t|%f\t|%f\t|%s\t|%f\t|\n",jou->jingdianbianhao,jou->jingdianmingcheng,jou->dianhua_tour,jou->chengrenpiaojia_tour,jou->ertongpiaojia_tour,jou->lianxiren,jou->shijian_tour);
printf("-------------------------------------------------------------------\n");
else
printf("\n没有信息");
getch();
clrscr();
void save(journey *head)
{ char filename[13];
FILE *fp;
journey *jou;
clrscr();
printf("请输入你想要保存的文件名");
scanf("%s",filename);
if((fp=fopen(filename,"wb"))==NULL)
{printf("cannot open file %s!\n",filename);
return;
jou=head;
while(jou!=NULL)
{fwrite(jou,sizeof(journey),1,fp);
jou=jou->next;
fclose(fp);
printf("saving.......");
printf("press any key to contiune.....\n");
getch();
journey *load()
{ journey *p,*q,*head=NULL;
FILE *fp;
char filename[13];
clrscr();
printf("\nenter the file name: ");
scanf("%s",filename);
if((fp=fopen(filename,"rb"))==NULL)
{ printf("cannot open file\n");
exit(1);
printf("\n-----liading file!-----");
p=(journey *)malloc(sizeof(journey));
if(!p)
{printf("out of memory!\n");
return(head);
head=p;
while(!feof(fp))
{ if(1!=fread(p,sizeof(journey),1,fp))
break;
p->next=(journey *)malloc(sizeof(journey));
if(!p->next)
{printf("out of memory!\n");
return head;
q=p;
p=p->next;
q->next=NULL;
fclose(fp);
printf("---you have success read data from file!!!---\n");
printf("press any key to contiune.....\n");
getch();
return(head);