《校园导游》课程设计报告.docx
《《校园导游》课程设计报告.docx》由会员分享,可在线阅读,更多相关《《校园导游》课程设计报告.docx(43页珍藏版)》请在冰豆网上搜索。
《校园导游》课程设计报告
课程设计报告
课程:
数据结构
学号:
0810111026
姓名:
章阳
班级:
08普本非师
教师:
王群芳
时间:
2010.6.30
合肥师范学院计算机科学与技术系
设计名称:
校园导游
日期:
2010年6月30日
设计内容:
用无向网表示学校的校园景点平面图,图中顶点表示主要景点,存放景点的编号、名称、简介等信息,图中的边表示景点间的道路,存放路径长度等信息。
设计目的与要求:
1.查询各景点的相关信息
2.查询图中任意两个景点间的最短路径
3.查询图中任意两个景点间的所有路径
4.增加、删除、更新有关景点和道路的信息
系统分析:
邻接表中的顶点的信息用数组存储,本系统为了实现景点的增加,删除功能,采用了顶点信息用链表做为存储结构,可以方便的实现这些功能。
在顶点的存储结构中,不仅有数据域(一个景点结构体,存放景点的编号,名称,介绍),指针域有指向下一个景点地址的nextV和指向其所对应边的下一个景点编号nextArc。
表结点里放有路径的长度和景点编号,这是本系统的存储方式。
本系统实现了对景点和道路的增加,删除,更新功能,且实现了任意景点之间的最短路径,和任意两景点的所有路径。
本系统可以按菜单的方式进行操作,并且在主菜单中设置了两个隐藏函数,其中操作6为Print用邻接表的形式显示景点编号和操作7为PrintMatrix用矩阵的形式显示道路长度,从而来检测对景点和道路的增加,删除,更新是否实现。
测试数据及结果:
上图中,共有10个景点,16条道路。
其中圆圈为各个景点(编号、名称、介绍),边为道路(长度)。
进入程序,选择是否使用默认数据:
创建图成功:
选择主操作1:
选择主操作2:
选择主操作3:
选择主操作4:
选择副操作1:
选择副操作2:
选择副操作3:
选择副操作4:
选择副操作5:
选择副操作6:
选择隐藏菜单Print:
选择隐藏菜单PrintMatrix:
设计体会:
本程序从设计到实现一共花了一个星期,感觉不是很难,但是要用心去做。
在这次课程设计中,我再次感觉到自己做程序要站在顾客角度上,让程序更加合理,更加人性化。
对于本次课程设计所用到的算法,我都想了很长时间,其中怎么输出所有路径,我还参考了网上的一些资料,最后用了广度优先搜索完成。
做完了课程设计,感觉自己一下轻松起来,程序出来了,我也该继续下了一个设计。
附录(源程序清单):
#include
usingnamespacestd;
#defineMAX_VERTEX_NUM50
typedefstructScenery
{
charsno[4];//景点编号
charsname[21];//景点名称
charstext[201];//景点介绍
}Scenery;//景点结构
typedefstructArcNode
intlength;//道路长度
structArcNode*next;
}ArcNode;//表结构
typedefstructVNode
Scenerysc;
structVNode*nextV;
ArcNode*nextArc;
}VNode;//顶点结构
//图结构
typedefstruct
VNode*V;//指向第一个顶点的指针
intvexnum,arcnum;
}Graph;
//矩阵结构
charvexs[MAX_VERTEX_NUM][4];//景点编号数组
intarcs[MAX_VERTEX_NUM][MAX_VERTEX_NUM];//道路长度矩阵
}Matrix;
//一行星号
voidStart(intn)
cout<<'\t';
for(inti=0;icout<<"*";cout<}//主菜单voidFMenu(){Start(60);cout<<"\t\t\t1)查询各景点的相关信息"<cout<<"\t\t\t2)查询图中任意两个景点间的最短路径"<cout<<"\t\t\t3)查询图中任意两个景点间的所有路径"<cout<<"\t\t\t4)增加、删除、更新景点和道路的信息"<cout<<"\t\t\t0)退出程序"<Start(60);}//副菜单voidSMenu(){Start(60);cout<<"\t\t\t1)增加景点信息"<cout<<"\t\t\t2)删除景点信息"<cout<<"\t\t\t3)更新景点信息"<cout<<"\t\t\t4)增加道路信息"<cout<<"\t\t\t5)删除道路信息"<cout<<"\t\t\t6)更新道路信息"<cout<<"\t\t\t0)返回主菜单"<Start(60);}//获得ArcNode地址VNode*GetAddress(char*sno,Graph&G){VNode*p;p=G.V;for(inti=0;i{if(!strcmp(sno,p->sc.sno))returnp;elsep=p->nextV;}returnNULL;}//系统默认建图voidDirectCreate(Graph&G){G.arcnum=16;G.vexnum=10;VNode*p1;VNode*p2;ArcNode*q1;ArcNode*q2;G.V=p1=(VNode*)malloc(sizeof(VNode));strcpy(p1->sc.sno,"001");strcpy(p1->sc.sname,"艺术楼");strcpy(p1->sc.stext,"艺术");q1=(ArcNode*)malloc(sizeof(ArcNode));p1->nextArc=q1;q1->length=60;strcpy(q1->sno,"009");q2=(ArcNode*)malloc(sizeof(ArcNode));q2->length=30;strcpy(q2->sno,"008");q2->next=NULL;q1->next=q2;p2=(VNode*)malloc(sizeof(VNode));strcpy(p2->sc.sno,"002");strcpy(p2->sc.sname,"实验楼");strcpy(p2->sc.stext,"实验");p1->nextV=p2;q1=(ArcNode*)malloc(sizeof(ArcNode));strcpy(q1->sno,"009");q1->length=40;p2->nextArc=q1;q2=(ArcNode*)malloc(sizeof(ArcNode));q2->length=150;strcpy(q2->sno,"006");q1->next=q2;q2->next=NULL;p1=(VNode*)malloc(sizeof(VNode));strcpy(p1->sc.sno,"003");strcpy(p1->sc.sname,"男生宿舍");strcpy(p1->sc.stext,"住宿");p2->nextV=p1;q1=(ArcNode*)malloc(sizeof(ArcNode));q1->length=30;strcpy(q1->sno,"010");p1->nextArc=q1;q2=(ArcNode*)malloc(sizeof(ArcNode));q2->length=75;strcpy(q2->sno,"005");q1->next=q2;q2->next=NULL;p2=(VNode*)malloc(sizeof(VNode));strcpy(p2->sc.sno,"004");strcpy(p2->sc.sname,"女生宿舍");strcpy(p2->sc.stext,"住宿");p1->nextV=p2;q1=(ArcNode*)malloc(sizeof(ArcNode));q1->length=30;strcpy(q1->sno,"003");p2->nextArc=q1;q2=(ArcNode*)malloc(sizeof(ArcNode));q2->length=100;strcpy(q2->sno,"007");q1->next=q2;q2->next=NULL;p1=(VNode*)malloc(sizeof(VNode));strcpy(p1->sc.sno,"005");strcpy(p1->sc.sname,"小湖");strcpy(p1->sc.stext,"风景");p2->nextV=p1;q1=(ArcNode*)malloc(sizeof(ArcNode));q1->length=70;strcpy(q1->sno,"009");p1->nextArc=q1;q2=(ArcNode*)malloc(sizeof(ArcNode));q2->length=100;strcpy(q2->sno,"006");q1->next=q2;q1=(ArcNode*)malloc(sizeof(ArcNode));q1->length=70;strcpy(q1->sno,"008");q2->next=q1;q2=(ArcNode*)malloc(sizeof(ArcNode));q2->length=120;strcpy(q2->sno,"007");q1->next=q2;q1=(ArcNode*)malloc(sizeof(ArcNode));q1->length=60;strcpy(q1->sno,"010");q2->next=q1;q2=(ArcNode*)malloc(sizeof(ArcNode));q2->length=75;strcpy(q2->sno,"003");q1->next=q2;q2->next=NULL;p2=(VNode*)malloc(sizeof(VNode));strcpy(p2->sc.sno,"006");strcpy(p2->sc.sname,"食堂");strcpy(p2->sc.stext,"吃饭");p1->nextV=p2;q1=(ArcNode*)malloc(sizeof(ArcNode));q1->length=70;strcpy(q1->sno,"009");p2->nextArc=q1;q2=(ArcNode*)malloc(sizeof(ArcNode));q2->length=150;strcpy(q2->sno,"002");q1->next=q2;q1=(ArcNode*)malloc(sizeof(ArcNode));q1->length=100;strcpy(q1->sno,"005");q2->next=q1;q1->next=NULL;p1=(VNode*)malloc(sizeof(VNode));strcpy(p1->sc.sno,"007");strcpy(p1->sc.sname,"图书馆");strcpy(p1->sc.stext,"借书");p2->nextV=p1;q1=(ArcNode*)malloc(sizeof(ArcNode));q1->length=120;strcpy(q1->sno,"005");p1->nextArc=q1;q2=(ArcNode*)malloc(sizeof(ArcNode));q2->length=100;strcpy(q2->sno,"004");q1->next=q2;q2->next=NULL;p2=(VNode*)malloc(sizeof(VNode));strcpy(p2->sc.sno,"008");strcpy(p2->sc.sname,"篮球场");strcpy(p2->sc.stext,"运动");p1->nextV=p2;q1=(ArcNode*)malloc(sizeof(ArcNode));q1->length=70;strcpy(q1->sno,"009");p2->nextArc=q1;q2=(ArcNode*)malloc(sizeof(ArcNode));q2->length=70;strcpy(q2->sno,"005");q1->next=q2;q1=(ArcNode*)malloc(sizeof(ArcNode));q1->length=30;strcpy(q1->sno,"001");q2->next=q1;q2=(ArcNode*)malloc(sizeof(ArcNode));q2->length=20;strcpy(q2->sno,"010");q1->next=q2;q2->next=NULL;p1=(VNode*)malloc(sizeof(VNode));strcpy(p1->sc.sno,"009");strcpy(p1->sc.sname,"教学楼");strcpy(p1->sc.stext,"教学");p2->nextV=p1;q1=(ArcNode*)malloc(sizeof(ArcNode));q1->length=70;strcpy(q1->sno,"005");p1->nextArc=q1;q2=(ArcNode*)malloc(sizeof(ArcNode));q2->length=70;strcpy(q2->sno,"006");q1->next=q2;q1=(ArcNode*)malloc(sizeof(ArcNode));q1->length=40;strcpy(q1->sno,"002");q2->next=q1;q2=(ArcNode*)malloc(sizeof(ArcNode));q2->length=60;strcpy(q2->sno,"001");q1->next=q2;q1=(ArcNode*)malloc(sizeof(ArcNode));q1->length=70;strcpy(q1->sno,"008");q2->next=q1;q1->next=NULL;p2=(VNode*)malloc(sizeof(VNode));strcpy(p2->sc.sno,"010");strcpy(p2->sc.sname,"足球场");strcpy(p2->sc.stext,"运动");p1->nextV=p2;q1=(ArcNode*)malloc(sizeof(ArcNode));q1->length=20;strcpy(q1->sno,"008");p2->nextArc=q1;q2=(ArcNode*)malloc(sizeof(ArcNode));q2->length=60;strcpy(q2->sno,"005");q1->next=q2;q1=(ArcNode*)malloc(sizeof(ArcNode));q1->length=30;strcpy(q1->sno,"003");q2->next=q1;q1->next=NULL;p2->nextV=NULL;}//创建图boolCreate(Graph&G){VNode*last;VNode*p;cout<<"请输入景点个数以及道路条数"<cin>>G.vexnum>>G.arcnum;if((G.vexnum<=0)||(G.arcnum<=0))returnfalse;G.V=(VNode*)malloc(sizeof(VNode));last=G.V;cout<<"请输入第1个景点的编号、名称、介绍"<cin>>last->sc.sno>>last->sc.sname>>last->sc.stext;last->nextArc=NULL;for(inti=1;i{p=(VNode*)malloc(sizeof(VNode));cout<<"请输入第"<cin>>p->sc.sno>>p->sc.sname>>p->sc.stext;p->nextArc=NULL;last->nextV=p;last=last->nextV;}last->nextV=NULL;charstartSno[4];charendSno[4];intlength;ArcNode*q=NULL;VNode*address=NULL;for(i=0;i{cout<<"请输入第"<cin>>startSno>>endSno>>length;address=GetAddress(startSno,G);q=(ArcNode*)malloc(sizeof(ArcNode));strcpy(q->sno,endSno);q->length=length;q->next=address->nextArc;address->nextArc=q;/*----------------无向网需正反两次-------------------*/address=GetAddress(endSno,G);q=(ArcNode*)malloc(sizeof(ArcNode));strcpy(q->sno,startSno);q->length=length;q->next=address->nextArc;address->nextArc=q;}returntrue;}//查询相关景点信息voidSearchScenery(Graph&G){intcount=0;VNode*p=G.V;charnoOrName[21];cout<<"请输入你想要查询的景点的编号或名称"<cin>>noOrName;for(inti=0;i{if(!(strcmp(noOrName,p->sc.sno)&&strcmp(noOrName,p->sc.sname))){cout<<"景点编号:"<sc.sno<cout<<"景点名称:"<sc.sname<cout<<"景点介绍:"<sc.stext<count++;break;}elsep=p->nextV;}if(!count)cout<<"查找失败!"<}//增加景点信息voidAddScenery(Graph&G){intcount=0;intflag=0;charsno[4];charsname[21];charstext[201];VNode*g=NULL;cout<<"请输入景点的编号:";cin>>sno;g=G.V;while(g){if(!strcmp(g->sc.sno,sno)){flag++;break;}elseg=g->nextV;}if(flag){cout<<"输入的景点编号重复,请重新插入!"<return;}cout<<"请输入景点的名称:";cin>>sname;cout<<"请输入景点的介绍:";cin>>stext;cout<VNode*p=G.V;VNode*parent=NULL;while(p){if(!strcmp(p->sc.sno,sno)){count++;break;}else{parent=p;p=p->nextV;}}if(!count){VNode*q;q=(VNode*)malloc(sizeof(VNode));strcpy(q->sc.sno,sno);strcpy(q->sc.sname,sname);strcpy(q->sc.stext,stext);parent->nextV=q;q->nextV=NULL;q->nextArc=NULL;G.vexnum++;cout<<"增加景点信息成功!"<}elsecout<<"增加景点编号重复,请重新增加!"<}//删除景点信息2voidDelete(char*sno1,char*sno2,Graph&G){intcount=0;VNode*address=NULL
cout<<"*";
cout<}//主菜单voidFMenu(){Start(60);cout<<"\t\t\t1)查询各景点的相关信息"<cout<<"\t\t\t2)查询图中任意两个景点间的最短路径"<cout<<"\t\t\t3)查询图中任意两个景点间的所有路径"<cout<<"\t\t\t4)增加、删除、更新景点和道路的信息"<cout<<"\t\t\t0)退出程序"<Start(60);}//副菜单voidSMenu(){Start(60);cout<<"\t\t\t1)增加景点信息"<cout<<"\t\t\t2)删除景点信息"<cout<<"\t\t\t3)更新景点信息"<cout<<"\t\t\t4)增加道路信息"<cout<<"\t\t\t5)删除道路信息"<cout<<"\t\t\t6)更新道路信息"<cout<<"\t\t\t0)返回主菜单"<Start(60);}//获得ArcNode地址VNode*GetAddress(char*sno,Graph&G){VNode*p;p=G.V;for(inti=0;i{if(!strcmp(sno,p->sc.sno))returnp;elsep=p->nextV;}returnNULL;}//系统默认建图voidDirectCreate(Graph&G){G.arcnum=16;G.vexnum=10;VNode*p1;VNode*p2;ArcNode*q1;ArcNode*q2;G.V=p1=(VNode*)malloc(sizeof(VNode));strcpy(p1->sc.sno,"001");strcpy(p1->sc.sname,"艺术楼");strcpy(p1->sc.stext,"艺术");q1=(ArcNode*)malloc(sizeof(ArcNode));p1->nextArc=q1;q1->length=60;strcpy(q1->sno,"009");q2=(ArcNode*)malloc(sizeof(ArcNode));q2->length=30;strcpy(q2->sno,"008");q2->next=NULL;q1->next=q2;p2=(VNode*)malloc(sizeof(VNode));strcpy(p2->sc.sno,"002");strcpy(p2->sc.sname,"实验楼");strcpy(p2->sc.stext,"实验");p1->nextV=p2;q1=(ArcNode*)malloc(sizeof(ArcNode));strcpy(q1->sno,"009");q1->length=40;p2->nextArc=q1;q2=(ArcNode*)malloc(sizeof(ArcNode));q2->length=150;strcpy(q2->sno,"006");q1->next=q2;q2->next=NULL;p1=(VNode*)malloc(sizeof(VNode));strcpy(p1->sc.sno,"003");strcpy(p1->sc.sname,"男生宿舍");strcpy(p1->sc.stext,"住宿");p2->nextV=p1;q1=(ArcNode*)malloc(sizeof(ArcNode));q1->length=30;strcpy(q1->sno,"010");p1->nextArc=q1;q2=(ArcNode*)malloc(sizeof(ArcNode));q2->length=75;strcpy(q2->sno,"005");q1->next=q2;q2->next=NULL;p2=(VNode*)malloc(sizeof(VNode));strcpy(p2->sc.sno,"004");strcpy(p2->sc.sname,"女生宿舍");strcpy(p2->sc.stext,"住宿");p1->nextV=p2;q1=(ArcNode*)malloc(sizeof(ArcNode));q1->length=30;strcpy(q1->sno,"003");p2->nextArc=q1;q2=(ArcNode*)malloc(sizeof(ArcNode));q2->length=100;strcpy(q2->sno,"007");q1->next=q2;q2->next=NULL;p1=(VNode*)malloc(sizeof(VNode));strcpy(p1->sc.sno,"005");strcpy(p1->sc.sname,"小湖");strcpy(p1->sc.stext,"风景");p2->nextV=p1;q1=(ArcNode*)malloc(sizeof(ArcNode));q1->length=70;strcpy(q1->sno,"009");p1->nextArc=q1;q2=(ArcNode*)malloc(sizeof(ArcNode));q2->length=100;strcpy(q2->sno,"006");q1->next=q2;q1=(ArcNode*)malloc(sizeof(ArcNode));q1->length=70;strcpy(q1->sno,"008");q2->next=q1;q2=(ArcNode*)malloc(sizeof(ArcNode));q2->length=120;strcpy(q2->sno,"007");q1->next=q2;q1=(ArcNode*)malloc(sizeof(ArcNode));q1->length=60;strcpy(q1->sno,"010");q2->next=q1;q2=(ArcNode*)malloc(sizeof(ArcNode));q2->length=75;strcpy(q2->sno,"003");q1->next=q2;q2->next=NULL;p2=(VNode*)malloc(sizeof(VNode));strcpy(p2->sc.sno,"006");strcpy(p2->sc.sname,"食堂");strcpy(p2->sc.stext,"吃饭");p1->nextV=p2;q1=(ArcNode*)malloc(sizeof(ArcNode));q1->length=70;strcpy(q1->sno,"009");p2->nextArc=q1;q2=(ArcNode*)malloc(sizeof(ArcNode));q2->length=150;strcpy(q2->sno,"002");q1->next=q2;q1=(ArcNode*)malloc(sizeof(ArcNode));q1->length=100;strcpy(q1->sno,"005");q2->next=q1;q1->next=NULL;p1=(VNode*)malloc(sizeof(VNode));strcpy(p1->sc.sno,"007");strcpy(p1->sc.sname,"图书馆");strcpy(p1->sc.stext,"借书");p2->nextV=p1;q1=(ArcNode*)malloc(sizeof(ArcNode));q1->length=120;strcpy(q1->sno,"005");p1->nextArc=q1;q2=(ArcNode*)malloc(sizeof(ArcNode));q2->length=100;strcpy(q2->sno,"004");q1->next=q2;q2->next=NULL;p2=(VNode*)malloc(sizeof(VNode));strcpy(p2->sc.sno,"008");strcpy(p2->sc.sname,"篮球场");strcpy(p2->sc.stext,"运动");p1->nextV=p2;q1=(ArcNode*)malloc(sizeof(ArcNode));q1->length=70;strcpy(q1->sno,"009");p2->nextArc=q1;q2=(ArcNode*)malloc(sizeof(ArcNode));q2->length=70;strcpy(q2->sno,"005");q1->next=q2;q1=(ArcNode*)malloc(sizeof(ArcNode));q1->length=30;strcpy(q1->sno,"001");q2->next=q1;q2=(ArcNode*)malloc(sizeof(ArcNode));q2->length=20;strcpy(q2->sno,"010");q1->next=q2;q2->next=NULL;p1=(VNode*)malloc(sizeof(VNode));strcpy(p1->sc.sno,"009");strcpy(p1->sc.sname,"教学楼");strcpy(p1->sc.stext,"教学");p2->nextV=p1;q1=(ArcNode*)malloc(sizeof(ArcNode));q1->length=70;strcpy(q1->sno,"005");p1->nextArc=q1;q2=(ArcNode*)malloc(sizeof(ArcNode));q2->length=70;strcpy(q2->sno,"006");q1->next=q2;q1=(ArcNode*)malloc(sizeof(ArcNode));q1->length=40;strcpy(q1->sno,"002");q2->next=q1;q2=(ArcNode*)malloc(sizeof(ArcNode));q2->length=60;strcpy(q2->sno,"001");q1->next=q2;q1=(ArcNode*)malloc(sizeof(ArcNode));q1->length=70;strcpy(q1->sno,"008");q2->next=q1;q1->next=NULL;p2=(VNode*)malloc(sizeof(VNode));strcpy(p2->sc.sno,"010");strcpy(p2->sc.sname,"足球场");strcpy(p2->sc.stext,"运动");p1->nextV=p2;q1=(ArcNode*)malloc(sizeof(ArcNode));q1->length=20;strcpy(q1->sno,"008");p2->nextArc=q1;q2=(ArcNode*)malloc(sizeof(ArcNode));q2->length=60;strcpy(q2->sno,"005");q1->next=q2;q1=(ArcNode*)malloc(sizeof(ArcNode));q1->length=30;strcpy(q1->sno,"003");q2->next=q1;q1->next=NULL;p2->nextV=NULL;}//创建图boolCreate(Graph&G){VNode*last;VNode*p;cout<<"请输入景点个数以及道路条数"<cin>>G.vexnum>>G.arcnum;if((G.vexnum<=0)||(G.arcnum<=0))returnfalse;G.V=(VNode*)malloc(sizeof(VNode));last=G.V;cout<<"请输入第1个景点的编号、名称、介绍"<cin>>last->sc.sno>>last->sc.sname>>last->sc.stext;last->nextArc=NULL;for(inti=1;i{p=(VNode*)malloc(sizeof(VNode));cout<<"请输入第"<cin>>p->sc.sno>>p->sc.sname>>p->sc.stext;p->nextArc=NULL;last->nextV=p;last=last->nextV;}last->nextV=NULL;charstartSno[4];charendSno[4];intlength;ArcNode*q=NULL;VNode*address=NULL;for(i=0;i{cout<<"请输入第"<cin>>startSno>>endSno>>length;address=GetAddress(startSno,G);q=(ArcNode*)malloc(sizeof(ArcNode));strcpy(q->sno,endSno);q->length=length;q->next=address->nextArc;address->nextArc=q;/*----------------无向网需正反两次-------------------*/address=GetAddress(endSno,G);q=(ArcNode*)malloc(sizeof(ArcNode));strcpy(q->sno,startSno);q->length=length;q->next=address->nextArc;address->nextArc=q;}returntrue;}//查询相关景点信息voidSearchScenery(Graph&G){intcount=0;VNode*p=G.V;charnoOrName[21];cout<<"请输入你想要查询的景点的编号或名称"<cin>>noOrName;for(inti=0;i{if(!(strcmp(noOrName,p->sc.sno)&&strcmp(noOrName,p->sc.sname))){cout<<"景点编号:"<sc.sno<cout<<"景点名称:"<sc.sname<cout<<"景点介绍:"<sc.stext<count++;break;}elsep=p->nextV;}if(!count)cout<<"查找失败!"<}//增加景点信息voidAddScenery(Graph&G){intcount=0;intflag=0;charsno[4];charsname[21];charstext[201];VNode*g=NULL;cout<<"请输入景点的编号:";cin>>sno;g=G.V;while(g){if(!strcmp(g->sc.sno,sno)){flag++;break;}elseg=g->nextV;}if(flag){cout<<"输入的景点编号重复,请重新插入!"<return;}cout<<"请输入景点的名称:";cin>>sname;cout<<"请输入景点的介绍:";cin>>stext;cout<VNode*p=G.V;VNode*parent=NULL;while(p){if(!strcmp(p->sc.sno,sno)){count++;break;}else{parent=p;p=p->nextV;}}if(!count){VNode*q;q=(VNode*)malloc(sizeof(VNode));strcpy(q->sc.sno,sno);strcpy(q->sc.sname,sname);strcpy(q->sc.stext,stext);parent->nextV=q;q->nextV=NULL;q->nextArc=NULL;G.vexnum++;cout<<"增加景点信息成功!"<}elsecout<<"增加景点编号重复,请重新增加!"<}//删除景点信息2voidDelete(char*sno1,char*sno2,Graph&G){intcount=0;VNode*address=NULL
}
//主菜单
voidFMenu()
Start(60);
cout<<"\t\t\t1)查询各景点的相关信息"<cout<<"\t\t\t2)查询图中任意两个景点间的最短路径"<cout<<"\t\t\t3)查询图中任意两个景点间的所有路径"<cout<<"\t\t\t4)增加、删除、更新景点和道路的信息"<cout<<"\t\t\t0)退出程序"<Start(60);}//副菜单voidSMenu(){Start(60);cout<<"\t\t\t1)增加景点信息"<cout<<"\t\t\t2)删除景点信息"<cout<<"\t\t\t3)更新景点信息"<cout<<"\t\t\t4)增加道路信息"<cout<<"\t\t\t5)删除道路信息"<cout<<"\t\t\t6)更新道路信息"<cout<<"\t\t\t0)返回主菜单"<Start(60);}//获得ArcNode地址VNode*GetAddress(char*sno,Graph&G){VNode*p;p=G.V;for(inti=0;i{if(!strcmp(sno,p->sc.sno))returnp;elsep=p->nextV;}returnNULL;}//系统默认建图voidDirectCreate(Graph&G){G.arcnum=16;G.vexnum=10;VNode*p1;VNode*p2;ArcNode*q1;ArcNode*q2;G.V=p1=(VNode*)malloc(sizeof(VNode));strcpy(p1->sc.sno,"001");strcpy(p1->sc.sname,"艺术楼");strcpy(p1->sc.stext,"艺术");q1=(ArcNode*)malloc(sizeof(ArcNode));p1->nextArc=q1;q1->length=60;strcpy(q1->sno,"009");q2=(ArcNode*)malloc(sizeof(ArcNode));q2->length=30;strcpy(q2->sno,"008");q2->next=NULL;q1->next=q2;p2=(VNode*)malloc(sizeof(VNode));strcpy(p2->sc.sno,"002");strcpy(p2->sc.sname,"实验楼");strcpy(p2->sc.stext,"实验");p1->nextV=p2;q1=(ArcNode*)malloc(sizeof(ArcNode));strcpy(q1->sno,"009");q1->length=40;p2->nextArc=q1;q2=(ArcNode*)malloc(sizeof(ArcNode));q2->length=150;strcpy(q2->sno,"006");q1->next=q2;q2->next=NULL;p1=(VNode*)malloc(sizeof(VNode));strcpy(p1->sc.sno,"003");strcpy(p1->sc.sname,"男生宿舍");strcpy(p1->sc.stext,"住宿");p2->nextV=p1;q1=(ArcNode*)malloc(sizeof(ArcNode));q1->length=30;strcpy(q1->sno,"010");p1->nextArc=q1;q2=(ArcNode*)malloc(sizeof(ArcNode));q2->length=75;strcpy(q2->sno,"005");q1->next=q2;q2->next=NULL;p2=(VNode*)malloc(sizeof(VNode));strcpy(p2->sc.sno,"004");strcpy(p2->sc.sname,"女生宿舍");strcpy(p2->sc.stext,"住宿");p1->nextV=p2;q1=(ArcNode*)malloc(sizeof(ArcNode));q1->length=30;strcpy(q1->sno,"003");p2->nextArc=q1;q2=(ArcNode*)malloc(sizeof(ArcNode));q2->length=100;strcpy(q2->sno,"007");q1->next=q2;q2->next=NULL;p1=(VNode*)malloc(sizeof(VNode));strcpy(p1->sc.sno,"005");strcpy(p1->sc.sname,"小湖");strcpy(p1->sc.stext,"风景");p2->nextV=p1;q1=(ArcNode*)malloc(sizeof(ArcNode));q1->length=70;strcpy(q1->sno,"009");p1->nextArc=q1;q2=(ArcNode*)malloc(sizeof(ArcNode));q2->length=100;strcpy(q2->sno,"006");q1->next=q2;q1=(ArcNode*)malloc(sizeof(ArcNode));q1->length=70;strcpy(q1->sno,"008");q2->next=q1;q2=(ArcNode*)malloc(sizeof(ArcNode));q2->length=120;strcpy(q2->sno,"007");q1->next=q2;q1=(ArcNode*)malloc(sizeof(ArcNode));q1->length=60;strcpy(q1->sno,"010");q2->next=q1;q2=(ArcNode*)malloc(sizeof(ArcNode));q2->length=75;strcpy(q2->sno,"003");q1->next=q2;q2->next=NULL;p2=(VNode*)malloc(sizeof(VNode));strcpy(p2->sc.sno,"006");strcpy(p2->sc.sname,"食堂");strcpy(p2->sc.stext,"吃饭");p1->nextV=p2;q1=(ArcNode*)malloc(sizeof(ArcNode));q1->length=70;strcpy(q1->sno,"009");p2->nextArc=q1;q2=(ArcNode*)malloc(sizeof(ArcNode));q2->length=150;strcpy(q2->sno,"002");q1->next=q2;q1=(ArcNode*)malloc(sizeof(ArcNode));q1->length=100;strcpy(q1->sno,"005");q2->next=q1;q1->next=NULL;p1=(VNode*)malloc(sizeof(VNode));strcpy(p1->sc.sno,"007");strcpy(p1->sc.sname,"图书馆");strcpy(p1->sc.stext,"借书");p2->nextV=p1;q1=(ArcNode*)malloc(sizeof(ArcNode));q1->length=120;strcpy(q1->sno,"005");p1->nextArc=q1;q2=(ArcNode*)malloc(sizeof(ArcNode));q2->length=100;strcpy(q2->sno,"004");q1->next=q2;q2->next=NULL;p2=(VNode*)malloc(sizeof(VNode));strcpy(p2->sc.sno,"008");strcpy(p2->sc.sname,"篮球场");strcpy(p2->sc.stext,"运动");p1->nextV=p2;q1=(ArcNode*)malloc(sizeof(ArcNode));q1->length=70;strcpy(q1->sno,"009");p2->nextArc=q1;q2=(ArcNode*)malloc(sizeof(ArcNode));q2->length=70;strcpy(q2->sno,"005");q1->next=q2;q1=(ArcNode*)malloc(sizeof(ArcNode));q1->length=30;strcpy(q1->sno,"001");q2->next=q1;q2=(ArcNode*)malloc(sizeof(ArcNode));q2->length=20;strcpy(q2->sno,"010");q1->next=q2;q2->next=NULL;p1=(VNode*)malloc(sizeof(VNode));strcpy(p1->sc.sno,"009");strcpy(p1->sc.sname,"教学楼");strcpy(p1->sc.stext,"教学");p2->nextV=p1;q1=(ArcNode*)malloc(sizeof(ArcNode));q1->length=70;strcpy(q1->sno,"005");p1->nextArc=q1;q2=(ArcNode*)malloc(sizeof(ArcNode));q2->length=70;strcpy(q2->sno,"006");q1->next=q2;q1=(ArcNode*)malloc(sizeof(ArcNode));q1->length=40;strcpy(q1->sno,"002");q2->next=q1;q2=(ArcNode*)malloc(sizeof(ArcNode));q2->length=60;strcpy(q2->sno,"001");q1->next=q2;q1=(ArcNode*)malloc(sizeof(ArcNode));q1->length=70;strcpy(q1->sno,"008");q2->next=q1;q1->next=NULL;p2=(VNode*)malloc(sizeof(VNode));strcpy(p2->sc.sno,"010");strcpy(p2->sc.sname,"足球场");strcpy(p2->sc.stext,"运动");p1->nextV=p2;q1=(ArcNode*)malloc(sizeof(ArcNode));q1->length=20;strcpy(q1->sno,"008");p2->nextArc=q1;q2=(ArcNode*)malloc(sizeof(ArcNode));q2->length=60;strcpy(q2->sno,"005");q1->next=q2;q1=(ArcNode*)malloc(sizeof(ArcNode));q1->length=30;strcpy(q1->sno,"003");q2->next=q1;q1->next=NULL;p2->nextV=NULL;}//创建图boolCreate(Graph&G){VNode*last;VNode*p;cout<<"请输入景点个数以及道路条数"<cin>>G.vexnum>>G.arcnum;if((G.vexnum<=0)||(G.arcnum<=0))returnfalse;G.V=(VNode*)malloc(sizeof(VNode));last=G.V;cout<<"请输入第1个景点的编号、名称、介绍"<cin>>last->sc.sno>>last->sc.sname>>last->sc.stext;last->nextArc=NULL;for(inti=1;i{p=(VNode*)malloc(sizeof(VNode));cout<<"请输入第"<cin>>p->sc.sno>>p->sc.sname>>p->sc.stext;p->nextArc=NULL;last->nextV=p;last=last->nextV;}last->nextV=NULL;charstartSno[4];charendSno[4];intlength;ArcNode*q=NULL;VNode*address=NULL;for(i=0;i{cout<<"请输入第"<cin>>startSno>>endSno>>length;address=GetAddress(startSno,G);q=(ArcNode*)malloc(sizeof(ArcNode));strcpy(q->sno,endSno);q->length=length;q->next=address->nextArc;address->nextArc=q;/*----------------无向网需正反两次-------------------*/address=GetAddress(endSno,G);q=(ArcNode*)malloc(sizeof(ArcNode));strcpy(q->sno,startSno);q->length=length;q->next=address->nextArc;address->nextArc=q;}returntrue;}//查询相关景点信息voidSearchScenery(Graph&G){intcount=0;VNode*p=G.V;charnoOrName[21];cout<<"请输入你想要查询的景点的编号或名称"<cin>>noOrName;for(inti=0;i{if(!(strcmp(noOrName,p->sc.sno)&&strcmp(noOrName,p->sc.sname))){cout<<"景点编号:"<sc.sno<cout<<"景点名称:"<sc.sname<cout<<"景点介绍:"<sc.stext<count++;break;}elsep=p->nextV;}if(!count)cout<<"查找失败!"<}//增加景点信息voidAddScenery(Graph&G){intcount=0;intflag=0;charsno[4];charsname[21];charstext[201];VNode*g=NULL;cout<<"请输入景点的编号:";cin>>sno;g=G.V;while(g){if(!strcmp(g->sc.sno,sno)){flag++;break;}elseg=g->nextV;}if(flag){cout<<"输入的景点编号重复,请重新插入!"<return;}cout<<"请输入景点的名称:";cin>>sname;cout<<"请输入景点的介绍:";cin>>stext;cout<VNode*p=G.V;VNode*parent=NULL;while(p){if(!strcmp(p->sc.sno,sno)){count++;break;}else{parent=p;p=p->nextV;}}if(!count){VNode*q;q=(VNode*)malloc(sizeof(VNode));strcpy(q->sc.sno,sno);strcpy(q->sc.sname,sname);strcpy(q->sc.stext,stext);parent->nextV=q;q->nextV=NULL;q->nextArc=NULL;G.vexnum++;cout<<"增加景点信息成功!"<}elsecout<<"增加景点编号重复,请重新增加!"<}//删除景点信息2voidDelete(char*sno1,char*sno2,Graph&G){intcount=0;VNode*address=NULL
cout<<"\t\t\t2)查询图中任意两个景点间的最短路径"<cout<<"\t\t\t3)查询图中任意两个景点间的所有路径"<cout<<"\t\t\t4)增加、删除、更新景点和道路的信息"<cout<<"\t\t\t0)退出程序"<Start(60);}//副菜单voidSMenu(){Start(60);cout<<"\t\t\t1)增加景点信息"<cout<<"\t\t\t2)删除景点信息"<cout<<"\t\t\t3)更新景点信息"<cout<<"\t\t\t4)增加道路信息"<cout<<"\t\t\t5)删除道路信息"<cout<<"\t\t\t6)更新道路信息"<cout<<"\t\t\t0)返回主菜单"<Start(60);}//获得ArcNode地址VNode*GetAddress(char*sno,Graph&G){VNode*p;p=G.V;for(inti=0;i{if(!strcmp(sno,p->sc.sno))returnp;elsep=p->nextV;}returnNULL;}//系统默认建图voidDirectCreate(Graph&G){G.arcnum=16;G.vexnum=10;VNode*p1;VNode*p2;ArcNode*q1;ArcNode*q2;G.V=p1=(VNode*)malloc(sizeof(VNode));strcpy(p1->sc.sno,"001");strcpy(p1->sc.sname,"艺术楼");strcpy(p1->sc.stext,"艺术");q1=(ArcNode*)malloc(sizeof(ArcNode));p1->nextArc=q1;q1->length=60;strcpy(q1->sno,"009");q2=(ArcNode*)malloc(sizeof(ArcNode));q2->length=30;strcpy(q2->sno,"008");q2->next=NULL;q1->next=q2;p2=(VNode*)malloc(sizeof(VNode));strcpy(p2->sc.sno,"002");strcpy(p2->sc.sname,"实验楼");strcpy(p2->sc.stext,"实验");p1->nextV=p2;q1=(ArcNode*)malloc(sizeof(ArcNode));strcpy(q1->sno,"009");q1->length=40;p2->nextArc=q1;q2=(ArcNode*)malloc(sizeof(ArcNode));q2->length=150;strcpy(q2->sno,"006");q1->next=q2;q2->next=NULL;p1=(VNode*)malloc(sizeof(VNode));strcpy(p1->sc.sno,"003");strcpy(p1->sc.sname,"男生宿舍");strcpy(p1->sc.stext,"住宿");p2->nextV=p1;q1=(ArcNode*)malloc(sizeof(ArcNode));q1->length=30;strcpy(q1->sno,"010");p1->nextArc=q1;q2=(ArcNode*)malloc(sizeof(ArcNode));q2->length=75;strcpy(q2->sno,"005");q1->next=q2;q2->next=NULL;p2=(VNode*)malloc(sizeof(VNode));strcpy(p2->sc.sno,"004");strcpy(p2->sc.sname,"女生宿舍");strcpy(p2->sc.stext,"住宿");p1->nextV=p2;q1=(ArcNode*)malloc(sizeof(ArcNode));q1->length=30;strcpy(q1->sno,"003");p2->nextArc=q1;q2=(ArcNode*)malloc(sizeof(ArcNode));q2->length=100;strcpy(q2->sno,"007");q1->next=q2;q2->next=NULL;p1=(VNode*)malloc(sizeof(VNode));strcpy(p1->sc.sno,"005");strcpy(p1->sc.sname,"小湖");strcpy(p1->sc.stext,"风景");p2->nextV=p1;q1=(ArcNode*)malloc(sizeof(ArcNode));q1->length=70;strcpy(q1->sno,"009");p1->nextArc=q1;q2=(ArcNode*)malloc(sizeof(ArcNode));q2->length=100;strcpy(q2->sno,"006");q1->next=q2;q1=(ArcNode*)malloc(sizeof(ArcNode));q1->length=70;strcpy(q1->sno,"008");q2->next=q1;q2=(ArcNode*)malloc(sizeof(ArcNode));q2->length=120;strcpy(q2->sno,"007");q1->next=q2;q1=(ArcNode*)malloc(sizeof(ArcNode));q1->length=60;strcpy(q1->sno,"010");q2->next=q1;q2=(ArcNode*)malloc(sizeof(ArcNode));q2->length=75;strcpy(q2->sno,"003");q1->next=q2;q2->next=NULL;p2=(VNode*)malloc(sizeof(VNode));strcpy(p2->sc.sno,"006");strcpy(p2->sc.sname,"食堂");strcpy(p2->sc.stext,"吃饭");p1->nextV=p2;q1=(ArcNode*)malloc(sizeof(ArcNode));q1->length=70;strcpy(q1->sno,"009");p2->nextArc=q1;q2=(ArcNode*)malloc(sizeof(ArcNode));q2->length=150;strcpy(q2->sno,"002");q1->next=q2;q1=(ArcNode*)malloc(sizeof(ArcNode));q1->length=100;strcpy(q1->sno,"005");q2->next=q1;q1->next=NULL;p1=(VNode*)malloc(sizeof(VNode));strcpy(p1->sc.sno,"007");strcpy(p1->sc.sname,"图书馆");strcpy(p1->sc.stext,"借书");p2->nextV=p1;q1=(ArcNode*)malloc(sizeof(ArcNode));q1->length=120;strcpy(q1->sno,"005");p1->nextArc=q1;q2=(ArcNode*)malloc(sizeof(ArcNode));q2->length=100;strcpy(q2->sno,"004");q1->next=q2;q2->next=NULL;p2=(VNode*)malloc(sizeof(VNode));strcpy(p2->sc.sno,"008");strcpy(p2->sc.sname,"篮球场");strcpy(p2->sc.stext,"运动");p1->nextV=p2;q1=(ArcNode*)malloc(sizeof(ArcNode));q1->length=70;strcpy(q1->sno,"009");p2->nextArc=q1;q2=(ArcNode*)malloc(sizeof(ArcNode));q2->length=70;strcpy(q2->sno,"005");q1->next=q2;q1=(ArcNode*)malloc(sizeof(ArcNode));q1->length=30;strcpy(q1->sno,"001");q2->next=q1;q2=(ArcNode*)malloc(sizeof(ArcNode));q2->length=20;strcpy(q2->sno,"010");q1->next=q2;q2->next=NULL;p1=(VNode*)malloc(sizeof(VNode));strcpy(p1->sc.sno,"009");strcpy(p1->sc.sname,"教学楼");strcpy(p1->sc.stext,"教学");p2->nextV=p1;q1=(ArcNode*)malloc(sizeof(ArcNode));q1->length=70;strcpy(q1->sno,"005");p1->nextArc=q1;q2=(ArcNode*)malloc(sizeof(ArcNode));q2->length=70;strcpy(q2->sno,"006");q1->next=q2;q1=(ArcNode*)malloc(sizeof(ArcNode));q1->length=40;strcpy(q1->sno,"002");q2->next=q1;q2=(ArcNode*)malloc(sizeof(ArcNode));q2->length=60;strcpy(q2->sno,"001");q1->next=q2;q1=(ArcNode*)malloc(sizeof(ArcNode));q1->length=70;strcpy(q1->sno,"008");q2->next=q1;q1->next=NULL;p2=(VNode*)malloc(sizeof(VNode));strcpy(p2->sc.sno,"010");strcpy(p2->sc.sname,"足球场");strcpy(p2->sc.stext,"运动");p1->nextV=p2;q1=(ArcNode*)malloc(sizeof(ArcNode));q1->length=20;strcpy(q1->sno,"008");p2->nextArc=q1;q2=(ArcNode*)malloc(sizeof(ArcNode));q2->length=60;strcpy(q2->sno,"005");q1->next=q2;q1=(ArcNode*)malloc(sizeof(ArcNode));q1->length=30;strcpy(q1->sno,"003");q2->next=q1;q1->next=NULL;p2->nextV=NULL;}//创建图boolCreate(Graph&G){VNode*last;VNode*p;cout<<"请输入景点个数以及道路条数"<cin>>G.vexnum>>G.arcnum;if((G.vexnum<=0)||(G.arcnum<=0))returnfalse;G.V=(VNode*)malloc(sizeof(VNode));last=G.V;cout<<"请输入第1个景点的编号、名称、介绍"<cin>>last->sc.sno>>last->sc.sname>>last->sc.stext;last->nextArc=NULL;for(inti=1;i{p=(VNode*)malloc(sizeof(VNode));cout<<"请输入第"<cin>>p->sc.sno>>p->sc.sname>>p->sc.stext;p->nextArc=NULL;last->nextV=p;last=last->nextV;}last->nextV=NULL;charstartSno[4];charendSno[4];intlength;ArcNode*q=NULL;VNode*address=NULL;for(i=0;i{cout<<"请输入第"<cin>>startSno>>endSno>>length;address=GetAddress(startSno,G);q=(ArcNode*)malloc(sizeof(ArcNode));strcpy(q->sno,endSno);q->length=length;q->next=address->nextArc;address->nextArc=q;/*----------------无向网需正反两次-------------------*/address=GetAddress(endSno,G);q=(ArcNode*)malloc(sizeof(ArcNode));strcpy(q->sno,startSno);q->length=length;q->next=address->nextArc;address->nextArc=q;}returntrue;}//查询相关景点信息voidSearchScenery(Graph&G){intcount=0;VNode*p=G.V;charnoOrName[21];cout<<"请输入你想要查询的景点的编号或名称"<cin>>noOrName;for(inti=0;i{if(!(strcmp(noOrName,p->sc.sno)&&strcmp(noOrName,p->sc.sname))){cout<<"景点编号:"<sc.sno<cout<<"景点名称:"<sc.sname<cout<<"景点介绍:"<sc.stext<count++;break;}elsep=p->nextV;}if(!count)cout<<"查找失败!"<}//增加景点信息voidAddScenery(Graph&G){intcount=0;intflag=0;charsno[4];charsname[21];charstext[201];VNode*g=NULL;cout<<"请输入景点的编号:";cin>>sno;g=G.V;while(g){if(!strcmp(g->sc.sno,sno)){flag++;break;}elseg=g->nextV;}if(flag){cout<<"输入的景点编号重复,请重新插入!"<return;}cout<<"请输入景点的名称:";cin>>sname;cout<<"请输入景点的介绍:";cin>>stext;cout<VNode*p=G.V;VNode*parent=NULL;while(p){if(!strcmp(p->sc.sno,sno)){count++;break;}else{parent=p;p=p->nextV;}}if(!count){VNode*q;q=(VNode*)malloc(sizeof(VNode));strcpy(q->sc.sno,sno);strcpy(q->sc.sname,sname);strcpy(q->sc.stext,stext);parent->nextV=q;q->nextV=NULL;q->nextArc=NULL;G.vexnum++;cout<<"增加景点信息成功!"<}elsecout<<"增加景点编号重复,请重新增加!"<}//删除景点信息2voidDelete(char*sno1,char*sno2,Graph&G){intcount=0;VNode*address=NULL
cout<<"\t\t\t3)查询图中任意两个景点间的所有路径"<cout<<"\t\t\t4)增加、删除、更新景点和道路的信息"<cout<<"\t\t\t0)退出程序"<Start(60);}//副菜单voidSMenu(){Start(60);cout<<"\t\t\t1)增加景点信息"<cout<<"\t\t\t2)删除景点信息"<cout<<"\t\t\t3)更新景点信息"<cout<<"\t\t\t4)增加道路信息"<cout<<"\t\t\t5)删除道路信息"<cout<<"\t\t\t6)更新道路信息"<cout<<"\t\t\t0)返回主菜单"<Start(60);}//获得ArcNode地址VNode*GetAddress(char*sno,Graph&G){VNode*p;p=G.V;for(inti=0;i{if(!strcmp(sno,p->sc.sno))returnp;elsep=p->nextV;}returnNULL;}//系统默认建图voidDirectCreate(Graph&G){G.arcnum=16;G.vexnum=10;VNode*p1;VNode*p2;ArcNode*q1;ArcNode*q2;G.V=p1=(VNode*)malloc(sizeof(VNode));strcpy(p1->sc.sno,"001");strcpy(p1->sc.sname,"艺术楼");strcpy(p1->sc.stext,"艺术");q1=(ArcNode*)malloc(sizeof(ArcNode));p1->nextArc=q1;q1->length=60;strcpy(q1->sno,"009");q2=(ArcNode*)malloc(sizeof(ArcNode));q2->length=30;strcpy(q2->sno,"008");q2->next=NULL;q1->next=q2;p2=(VNode*)malloc(sizeof(VNode));strcpy(p2->sc.sno,"002");strcpy(p2->sc.sname,"实验楼");strcpy(p2->sc.stext,"实验");p1->nextV=p2;q1=(ArcNode*)malloc(sizeof(ArcNode));strcpy(q1->sno,"009");q1->length=40;p2->nextArc=q1;q2=(ArcNode*)malloc(sizeof(ArcNode));q2->length=150;strcpy(q2->sno,"006");q1->next=q2;q2->next=NULL;p1=(VNode*)malloc(sizeof(VNode));strcpy(p1->sc.sno,"003");strcpy(p1->sc.sname,"男生宿舍");strcpy(p1->sc.stext,"住宿");p2->nextV=p1;q1=(ArcNode*)malloc(sizeof(ArcNode));q1->length=30;strcpy(q1->sno,"010");p1->nextArc=q1;q2=(ArcNode*)malloc(sizeof(ArcNode));q2->length=75;strcpy(q2->sno,"005");q1->next=q2;q2->next=NULL;p2=(VNode*)malloc(sizeof(VNode));strcpy(p2->sc.sno,"004");strcpy(p2->sc.sname,"女生宿舍");strcpy(p2->sc.stext,"住宿");p1->nextV=p2;q1=(ArcNode*)malloc(sizeof(ArcNode));q1->length=30;strcpy(q1->sno,"003");p2->nextArc=q1;q2=(ArcNode*)malloc(sizeof(ArcNode));q2->length=100;strcpy(q2->sno,"007");q1->next=q2;q2->next=NULL;p1=(VNode*)malloc(sizeof(VNode));strcpy(p1->sc.sno,"005");strcpy(p1->sc.sname,"小湖");strcpy(p1->sc.stext,"风景");p2->nextV=p1;q1=(ArcNode*)malloc(sizeof(ArcNode));q1->length=70;strcpy(q1->sno,"009");p1->nextArc=q1;q2=(ArcNode*)malloc(sizeof(ArcNode));q2->length=100;strcpy(q2->sno,"006");q1->next=q2;q1=(ArcNode*)malloc(sizeof(ArcNode));q1->length=70;strcpy(q1->sno,"008");q2->next=q1;q2=(ArcNode*)malloc(sizeof(ArcNode));q2->length=120;strcpy(q2->sno,"007");q1->next=q2;q1=(ArcNode*)malloc(sizeof(ArcNode));q1->length=60;strcpy(q1->sno,"010");q2->next=q1;q2=(ArcNode*)malloc(sizeof(ArcNode));q2->length=75;strcpy(q2->sno,"003");q1->next=q2;q2->next=NULL;p2=(VNode*)malloc(sizeof(VNode));strcpy(p2->sc.sno,"006");strcpy(p2->sc.sname,"食堂");strcpy(p2->sc.stext,"吃饭");p1->nextV=p2;q1=(ArcNode*)malloc(sizeof(ArcNode));q1->length=70;strcpy(q1->sno,"009");p2->nextArc=q1;q2=(ArcNode*)malloc(sizeof(ArcNode));q2->length=150;strcpy(q2->sno,"002");q1->next=q2;q1=(ArcNode*)malloc(sizeof(ArcNode));q1->length=100;strcpy(q1->sno,"005");q2->next=q1;q1->next=NULL;p1=(VNode*)malloc(sizeof(VNode));strcpy(p1->sc.sno,"007");strcpy(p1->sc.sname,"图书馆");strcpy(p1->sc.stext,"借书");p2->nextV=p1;q1=(ArcNode*)malloc(sizeof(ArcNode));q1->length=120;strcpy(q1->sno,"005");p1->nextArc=q1;q2=(ArcNode*)malloc(sizeof(ArcNode));q2->length=100;strcpy(q2->sno,"004");q1->next=q2;q2->next=NULL;p2=(VNode*)malloc(sizeof(VNode));strcpy(p2->sc.sno,"008");strcpy(p2->sc.sname,"篮球场");strcpy(p2->sc.stext,"运动");p1->nextV=p2;q1=(ArcNode*)malloc(sizeof(ArcNode));q1->length=70;strcpy(q1->sno,"009");p2->nextArc=q1;q2=(ArcNode*)malloc(sizeof(ArcNode));q2->length=70;strcpy(q2->sno,"005");q1->next=q2;q1=(ArcNode*)malloc(sizeof(ArcNode));q1->length=30;strcpy(q1->sno,"001");q2->next=q1;q2=(ArcNode*)malloc(sizeof(ArcNode));q2->length=20;strcpy(q2->sno,"010");q1->next=q2;q2->next=NULL;p1=(VNode*)malloc(sizeof(VNode));strcpy(p1->sc.sno,"009");strcpy(p1->sc.sname,"教学楼");strcpy(p1->sc.stext,"教学");p2->nextV=p1;q1=(ArcNode*)malloc(sizeof(ArcNode));q1->length=70;strcpy(q1->sno,"005");p1->nextArc=q1;q2=(ArcNode*)malloc(sizeof(ArcNode));q2->length=70;strcpy(q2->sno,"006");q1->next=q2;q1=(ArcNode*)malloc(sizeof(ArcNode));q1->length=40;strcpy(q1->sno,"002");q2->next=q1;q2=(ArcNode*)malloc(sizeof(ArcNode));q2->length=60;strcpy(q2->sno,"001");q1->next=q2;q1=(ArcNode*)malloc(sizeof(ArcNode));q1->length=70;strcpy(q1->sno,"008");q2->next=q1;q1->next=NULL;p2=(VNode*)malloc(sizeof(VNode));strcpy(p2->sc.sno,"010");strcpy(p2->sc.sname,"足球场");strcpy(p2->sc.stext,"运动");p1->nextV=p2;q1=(ArcNode*)malloc(sizeof(ArcNode));q1->length=20;strcpy(q1->sno,"008");p2->nextArc=q1;q2=(ArcNode*)malloc(sizeof(ArcNode));q2->length=60;strcpy(q2->sno,"005");q1->next=q2;q1=(ArcNode*)malloc(sizeof(ArcNode));q1->length=30;strcpy(q1->sno,"003");q2->next=q1;q1->next=NULL;p2->nextV=NULL;}//创建图boolCreate(Graph&G){VNode*last;VNode*p;cout<<"请输入景点个数以及道路条数"<cin>>G.vexnum>>G.arcnum;if((G.vexnum<=0)||(G.arcnum<=0))returnfalse;G.V=(VNode*)malloc(sizeof(VNode));last=G.V;cout<<"请输入第1个景点的编号、名称、介绍"<cin>>last->sc.sno>>last->sc.sname>>last->sc.stext;last->nextArc=NULL;for(inti=1;i{p=(VNode*)malloc(sizeof(VNode));cout<<"请输入第"<cin>>p->sc.sno>>p->sc.sname>>p->sc.stext;p->nextArc=NULL;last->nextV=p;last=last->nextV;}last->nextV=NULL;charstartSno[4];charendSno[4];intlength;ArcNode*q=NULL;VNode*address=NULL;for(i=0;i{cout<<"请输入第"<cin>>startSno>>endSno>>length;address=GetAddress(startSno,G);q=(ArcNode*)malloc(sizeof(ArcNode));strcpy(q->sno,endSno);q->length=length;q->next=address->nextArc;address->nextArc=q;/*----------------无向网需正反两次-------------------*/address=GetAddress(endSno,G);q=(ArcNode*)malloc(sizeof(ArcNode));strcpy(q->sno,startSno);q->length=length;q->next=address->nextArc;address->nextArc=q;}returntrue;}//查询相关景点信息voidSearchScenery(Graph&G){intcount=0;VNode*p=G.V;charnoOrName[21];cout<<"请输入你想要查询的景点的编号或名称"<cin>>noOrName;for(inti=0;i{if(!(strcmp(noOrName,p->sc.sno)&&strcmp(noOrName,p->sc.sname))){cout<<"景点编号:"<sc.sno<cout<<"景点名称:"<sc.sname<cout<<"景点介绍:"<sc.stext<count++;break;}elsep=p->nextV;}if(!count)cout<<"查找失败!"<}//增加景点信息voidAddScenery(Graph&G){intcount=0;intflag=0;charsno[4];charsname[21];charstext[201];VNode*g=NULL;cout<<"请输入景点的编号:";cin>>sno;g=G.V;while(g){if(!strcmp(g->sc.sno,sno)){flag++;break;}elseg=g->nextV;}if(flag){cout<<"输入的景点编号重复,请重新插入!"<return;}cout<<"请输入景点的名称:";cin>>sname;cout<<"请输入景点的介绍:";cin>>stext;cout<VNode*p=G.V;VNode*parent=NULL;while(p){if(!strcmp(p->sc.sno,sno)){count++;break;}else{parent=p;p=p->nextV;}}if(!count){VNode*q;q=(VNode*)malloc(sizeof(VNode));strcpy(q->sc.sno,sno);strcpy(q->sc.sname,sname);strcpy(q->sc.stext,stext);parent->nextV=q;q->nextV=NULL;q->nextArc=NULL;G.vexnum++;cout<<"增加景点信息成功!"<}elsecout<<"增加景点编号重复,请重新增加!"<}//删除景点信息2voidDelete(char*sno1,char*sno2,Graph&G){intcount=0;VNode*address=NULL
cout<<"\t\t\t4)增加、删除、更新景点和道路的信息"<cout<<"\t\t\t0)退出程序"<Start(60);}//副菜单voidSMenu(){Start(60);cout<<"\t\t\t1)增加景点信息"<cout<<"\t\t\t2)删除景点信息"<cout<<"\t\t\t3)更新景点信息"<cout<<"\t\t\t4)增加道路信息"<cout<<"\t\t\t5)删除道路信息"<cout<<"\t\t\t6)更新道路信息"<cout<<"\t\t\t0)返回主菜单"<Start(60);}//获得ArcNode地址VNode*GetAddress(char*sno,Graph&G){VNode*p;p=G.V;for(inti=0;i{if(!strcmp(sno,p->sc.sno))returnp;elsep=p->nextV;}returnNULL;}//系统默认建图voidDirectCreate(Graph&G){G.arcnum=16;G.vexnum=10;VNode*p1;VNode*p2;ArcNode*q1;ArcNode*q2;G.V=p1=(VNode*)malloc(sizeof(VNode));strcpy(p1->sc.sno,"001");strcpy(p1->sc.sname,"艺术楼");strcpy(p1->sc.stext,"艺术");q1=(ArcNode*)malloc(sizeof(ArcNode));p1->nextArc=q1;q1->length=60;strcpy(q1->sno,"009");q2=(ArcNode*)malloc(sizeof(ArcNode));q2->length=30;strcpy(q2->sno,"008");q2->next=NULL;q1->next=q2;p2=(VNode*)malloc(sizeof(VNode));strcpy(p2->sc.sno,"002");strcpy(p2->sc.sname,"实验楼");strcpy(p2->sc.stext,"实验");p1->nextV=p2;q1=(ArcNode*)malloc(sizeof(ArcNode));strcpy(q1->sno,"009");q1->length=40;p2->nextArc=q1;q2=(ArcNode*)malloc(sizeof(ArcNode));q2->length=150;strcpy(q2->sno,"006");q1->next=q2;q2->next=NULL;p1=(VNode*)malloc(sizeof(VNode));strcpy(p1->sc.sno,"003");strcpy(p1->sc.sname,"男生宿舍");strcpy(p1->sc.stext,"住宿");p2->nextV=p1;q1=(ArcNode*)malloc(sizeof(ArcNode));q1->length=30;strcpy(q1->sno,"010");p1->nextArc=q1;q2=(ArcNode*)malloc(sizeof(ArcNode));q2->length=75;strcpy(q2->sno,"005");q1->next=q2;q2->next=NULL;p2=(VNode*)malloc(sizeof(VNode));strcpy(p2->sc.sno,"004");strcpy(p2->sc.sname,"女生宿舍");strcpy(p2->sc.stext,"住宿");p1->nextV=p2;q1=(ArcNode*)malloc(sizeof(ArcNode));q1->length=30;strcpy(q1->sno,"003");p2->nextArc=q1;q2=(ArcNode*)malloc(sizeof(ArcNode));q2->length=100;strcpy(q2->sno,"007");q1->next=q2;q2->next=NULL;p1=(VNode*)malloc(sizeof(VNode));strcpy(p1->sc.sno,"005");strcpy(p1->sc.sname,"小湖");strcpy(p1->sc.stext,"风景");p2->nextV=p1;q1=(ArcNode*)malloc(sizeof(ArcNode));q1->length=70;strcpy(q1->sno,"009");p1->nextArc=q1;q2=(ArcNode*)malloc(sizeof(ArcNode));q2->length=100;strcpy(q2->sno,"006");q1->next=q2;q1=(ArcNode*)malloc(sizeof(ArcNode));q1->length=70;strcpy(q1->sno,"008");q2->next=q1;q2=(ArcNode*)malloc(sizeof(ArcNode));q2->length=120;strcpy(q2->sno,"007");q1->next=q2;q1=(ArcNode*)malloc(sizeof(ArcNode));q1->length=60;strcpy(q1->sno,"010");q2->next=q1;q2=(ArcNode*)malloc(sizeof(ArcNode));q2->length=75;strcpy(q2->sno,"003");q1->next=q2;q2->next=NULL;p2=(VNode*)malloc(sizeof(VNode));strcpy(p2->sc.sno,"006");strcpy(p2->sc.sname,"食堂");strcpy(p2->sc.stext,"吃饭");p1->nextV=p2;q1=(ArcNode*)malloc(sizeof(ArcNode));q1->length=70;strcpy(q1->sno,"009");p2->nextArc=q1;q2=(ArcNode*)malloc(sizeof(ArcNode));q2->length=150;strcpy(q2->sno,"002");q1->next=q2;q1=(ArcNode*)malloc(sizeof(ArcNode));q1->length=100;strcpy(q1->sno,"005");q2->next=q1;q1->next=NULL;p1=(VNode*)malloc(sizeof(VNode));strcpy(p1->sc.sno,"007");strcpy(p1->sc.sname,"图书馆");strcpy(p1->sc.stext,"借书");p2->nextV=p1;q1=(ArcNode*)malloc(sizeof(ArcNode));q1->length=120;strcpy(q1->sno,"005");p1->nextArc=q1;q2=(ArcNode*)malloc(sizeof(ArcNode));q2->length=100;strcpy(q2->sno,"004");q1->next=q2;q2->next=NULL;p2=(VNode*)malloc(sizeof(VNode));strcpy(p2->sc.sno,"008");strcpy(p2->sc.sname,"篮球场");strcpy(p2->sc.stext,"运动");p1->nextV=p2;q1=(ArcNode*)malloc(sizeof(ArcNode));q1->length=70;strcpy(q1->sno,"009");p2->nextArc=q1;q2=(ArcNode*)malloc(sizeof(ArcNode));q2->length=70;strcpy(q2->sno,"005");q1->next=q2;q1=(ArcNode*)malloc(sizeof(ArcNode));q1->length=30;strcpy(q1->sno,"001");q2->next=q1;q2=(ArcNode*)malloc(sizeof(ArcNode));q2->length=20;strcpy(q2->sno,"010");q1->next=q2;q2->next=NULL;p1=(VNode*)malloc(sizeof(VNode));strcpy(p1->sc.sno,"009");strcpy(p1->sc.sname,"教学楼");strcpy(p1->sc.stext,"教学");p2->nextV=p1;q1=(ArcNode*)malloc(sizeof(ArcNode));q1->length=70;strcpy(q1->sno,"005");p1->nextArc=q1;q2=(ArcNode*)malloc(sizeof(ArcNode));q2->length=70;strcpy(q2->sno,"006");q1->next=q2;q1=(ArcNode*)malloc(sizeof(ArcNode));q1->length=40;strcpy(q1->sno,"002");q2->next=q1;q2=(ArcNode*)malloc(sizeof(ArcNode));q2->length=60;strcpy(q2->sno,"001");q1->next=q2;q1=(ArcNode*)malloc(sizeof(ArcNode));q1->length=70;strcpy(q1->sno,"008");q2->next=q1;q1->next=NULL;p2=(VNode*)malloc(sizeof(VNode));strcpy(p2->sc.sno,"010");strcpy(p2->sc.sname,"足球场");strcpy(p2->sc.stext,"运动");p1->nextV=p2;q1=(ArcNode*)malloc(sizeof(ArcNode));q1->length=20;strcpy(q1->sno,"008");p2->nextArc=q1;q2=(ArcNode*)malloc(sizeof(ArcNode));q2->length=60;strcpy(q2->sno,"005");q1->next=q2;q1=(ArcNode*)malloc(sizeof(ArcNode));q1->length=30;strcpy(q1->sno,"003");q2->next=q1;q1->next=NULL;p2->nextV=NULL;}//创建图boolCreate(Graph&G){VNode*last;VNode*p;cout<<"请输入景点个数以及道路条数"<cin>>G.vexnum>>G.arcnum;if((G.vexnum<=0)||(G.arcnum<=0))returnfalse;G.V=(VNode*)malloc(sizeof(VNode));last=G.V;cout<<"请输入第1个景点的编号、名称、介绍"<cin>>last->sc.sno>>last->sc.sname>>last->sc.stext;last->nextArc=NULL;for(inti=1;i{p=(VNode*)malloc(sizeof(VNode));cout<<"请输入第"<cin>>p->sc.sno>>p->sc.sname>>p->sc.stext;p->nextArc=NULL;last->nextV=p;last=last->nextV;}last->nextV=NULL;charstartSno[4];charendSno[4];intlength;ArcNode*q=NULL;VNode*address=NULL;for(i=0;i{cout<<"请输入第"<cin>>startSno>>endSno>>length;address=GetAddress(startSno,G);q=(ArcNode*)malloc(sizeof(ArcNode));strcpy(q->sno,endSno);q->length=length;q->next=address->nextArc;address->nextArc=q;/*----------------无向网需正反两次-------------------*/address=GetAddress(endSno,G);q=(ArcNode*)malloc(sizeof(ArcNode));strcpy(q->sno,startSno);q->length=length;q->next=address->nextArc;address->nextArc=q;}returntrue;}//查询相关景点信息voidSearchScenery(Graph&G){intcount=0;VNode*p=G.V;charnoOrName[21];cout<<"请输入你想要查询的景点的编号或名称"<cin>>noOrName;for(inti=0;i{if(!(strcmp(noOrName,p->sc.sno)&&strcmp(noOrName,p->sc.sname))){cout<<"景点编号:"<sc.sno<cout<<"景点名称:"<sc.sname<cout<<"景点介绍:"<sc.stext<count++;break;}elsep=p->nextV;}if(!count)cout<<"查找失败!"<}//增加景点信息voidAddScenery(Graph&G){intcount=0;intflag=0;charsno[4];charsname[21];charstext[201];VNode*g=NULL;cout<<"请输入景点的编号:";cin>>sno;g=G.V;while(g){if(!strcmp(g->sc.sno,sno)){flag++;break;}elseg=g->nextV;}if(flag){cout<<"输入的景点编号重复,请重新插入!"<return;}cout<<"请输入景点的名称:";cin>>sname;cout<<"请输入景点的介绍:";cin>>stext;cout<VNode*p=G.V;VNode*parent=NULL;while(p){if(!strcmp(p->sc.sno,sno)){count++;break;}else{parent=p;p=p->nextV;}}if(!count){VNode*q;q=(VNode*)malloc(sizeof(VNode));strcpy(q->sc.sno,sno);strcpy(q->sc.sname,sname);strcpy(q->sc.stext,stext);parent->nextV=q;q->nextV=NULL;q->nextArc=NULL;G.vexnum++;cout<<"增加景点信息成功!"<}elsecout<<"增加景点编号重复,请重新增加!"<}//删除景点信息2voidDelete(char*sno1,char*sno2,Graph&G){intcount=0;VNode*address=NULL
cout<<"\t\t\t0)退出程序"<Start(60);}//副菜单voidSMenu(){Start(60);cout<<"\t\t\t1)增加景点信息"<cout<<"\t\t\t2)删除景点信息"<cout<<"\t\t\t3)更新景点信息"<cout<<"\t\t\t4)增加道路信息"<cout<<"\t\t\t5)删除道路信息"<cout<<"\t\t\t6)更新道路信息"<cout<<"\t\t\t0)返回主菜单"<Start(60);}//获得ArcNode地址VNode*GetAddress(char*sno,Graph&G){VNode*p;p=G.V;for(inti=0;i{if(!strcmp(sno,p->sc.sno))returnp;elsep=p->nextV;}returnNULL;}//系统默认建图voidDirectCreate(Graph&G){G.arcnum=16;G.vexnum=10;VNode*p1;VNode*p2;ArcNode*q1;ArcNode*q2;G.V=p1=(VNode*)malloc(sizeof(VNode));strcpy(p1->sc.sno,"001");strcpy(p1->sc.sname,"艺术楼");strcpy(p1->sc.stext,"艺术");q1=(ArcNode*)malloc(sizeof(ArcNode));p1->nextArc=q1;q1->length=60;strcpy(q1->sno,"009");q2=(ArcNode*)malloc(sizeof(ArcNode));q2->length=30;strcpy(q2->sno,"008");q2->next=NULL;q1->next=q2;p2=(VNode*)malloc(sizeof(VNode));strcpy(p2->sc.sno,"002");strcpy(p2->sc.sname,"实验楼");strcpy(p2->sc.stext,"实验");p1->nextV=p2;q1=(ArcNode*)malloc(sizeof(ArcNode));strcpy(q1->sno,"009");q1->length=40;p2->nextArc=q1;q2=(ArcNode*)malloc(sizeof(ArcNode));q2->length=150;strcpy(q2->sno,"006");q1->next=q2;q2->next=NULL;p1=(VNode*)malloc(sizeof(VNode));strcpy(p1->sc.sno,"003");strcpy(p1->sc.sname,"男生宿舍");strcpy(p1->sc.stext,"住宿");p2->nextV=p1;q1=(ArcNode*)malloc(sizeof(ArcNode));q1->length=30;strcpy(q1->sno,"010");p1->nextArc=q1;q2=(ArcNode*)malloc(sizeof(ArcNode));q2->length=75;strcpy(q2->sno,"005");q1->next=q2;q2->next=NULL;p2=(VNode*)malloc(sizeof(VNode));strcpy(p2->sc.sno,"004");strcpy(p2->sc.sname,"女生宿舍");strcpy(p2->sc.stext,"住宿");p1->nextV=p2;q1=(ArcNode*)malloc(sizeof(ArcNode));q1->length=30;strcpy(q1->sno,"003");p2->nextArc=q1;q2=(ArcNode*)malloc(sizeof(ArcNode));q2->length=100;strcpy(q2->sno,"007");q1->next=q2;q2->next=NULL;p1=(VNode*)malloc(sizeof(VNode));strcpy(p1->sc.sno,"005");strcpy(p1->sc.sname,"小湖");strcpy(p1->sc.stext,"风景");p2->nextV=p1;q1=(ArcNode*)malloc(sizeof(ArcNode));q1->length=70;strcpy(q1->sno,"009");p1->nextArc=q1;q2=(ArcNode*)malloc(sizeof(ArcNode));q2->length=100;strcpy(q2->sno,"006");q1->next=q2;q1=(ArcNode*)malloc(sizeof(ArcNode));q1->length=70;strcpy(q1->sno,"008");q2->next=q1;q2=(ArcNode*)malloc(sizeof(ArcNode));q2->length=120;strcpy(q2->sno,"007");q1->next=q2;q1=(ArcNode*)malloc(sizeof(ArcNode));q1->length=60;strcpy(q1->sno,"010");q2->next=q1;q2=(ArcNode*)malloc(sizeof(ArcNode));q2->length=75;strcpy(q2->sno,"003");q1->next=q2;q2->next=NULL;p2=(VNode*)malloc(sizeof(VNode));strcpy(p2->sc.sno,"006");strcpy(p2->sc.sname,"食堂");strcpy(p2->sc.stext,"吃饭");p1->nextV=p2;q1=(ArcNode*)malloc(sizeof(ArcNode));q1->length=70;strcpy(q1->sno,"009");p2->nextArc=q1;q2=(ArcNode*)malloc(sizeof(ArcNode));q2->length=150;strcpy(q2->sno,"002");q1->next=q2;q1=(ArcNode*)malloc(sizeof(ArcNode));q1->length=100;strcpy(q1->sno,"005");q2->next=q1;q1->next=NULL;p1=(VNode*)malloc(sizeof(VNode));strcpy(p1->sc.sno,"007");strcpy(p1->sc.sname,"图书馆");strcpy(p1->sc.stext,"借书");p2->nextV=p1;q1=(ArcNode*)malloc(sizeof(ArcNode));q1->length=120;strcpy(q1->sno,"005");p1->nextArc=q1;q2=(ArcNode*)malloc(sizeof(ArcNode));q2->length=100;strcpy(q2->sno,"004");q1->next=q2;q2->next=NULL;p2=(VNode*)malloc(sizeof(VNode));strcpy(p2->sc.sno,"008");strcpy(p2->sc.sname,"篮球场");strcpy(p2->sc.stext,"运动");p1->nextV=p2;q1=(ArcNode*)malloc(sizeof(ArcNode));q1->length=70;strcpy(q1->sno,"009");p2->nextArc=q1;q2=(ArcNode*)malloc(sizeof(ArcNode));q2->length=70;strcpy(q2->sno,"005");q1->next=q2;q1=(ArcNode*)malloc(sizeof(ArcNode));q1->length=30;strcpy(q1->sno,"001");q2->next=q1;q2=(ArcNode*)malloc(sizeof(ArcNode));q2->length=20;strcpy(q2->sno,"010");q1->next=q2;q2->next=NULL;p1=(VNode*)malloc(sizeof(VNode));strcpy(p1->sc.sno,"009");strcpy(p1->sc.sname,"教学楼");strcpy(p1->sc.stext,"教学");p2->nextV=p1;q1=(ArcNode*)malloc(sizeof(ArcNode));q1->length=70;strcpy(q1->sno,"005");p1->nextArc=q1;q2=(ArcNode*)malloc(sizeof(ArcNode));q2->length=70;strcpy(q2->sno,"006");q1->next=q2;q1=(ArcNode*)malloc(sizeof(ArcNode));q1->length=40;strcpy(q1->sno,"002");q2->next=q1;q2=(ArcNode*)malloc(sizeof(ArcNode));q2->length=60;strcpy(q2->sno,"001");q1->next=q2;q1=(ArcNode*)malloc(sizeof(ArcNode));q1->length=70;strcpy(q1->sno,"008");q2->next=q1;q1->next=NULL;p2=(VNode*)malloc(sizeof(VNode));strcpy(p2->sc.sno,"010");strcpy(p2->sc.sname,"足球场");strcpy(p2->sc.stext,"运动");p1->nextV=p2;q1=(ArcNode*)malloc(sizeof(ArcNode));q1->length=20;strcpy(q1->sno,"008");p2->nextArc=q1;q2=(ArcNode*)malloc(sizeof(ArcNode));q2->length=60;strcpy(q2->sno,"005");q1->next=q2;q1=(ArcNode*)malloc(sizeof(ArcNode));q1->length=30;strcpy(q1->sno,"003");q2->next=q1;q1->next=NULL;p2->nextV=NULL;}//创建图boolCreate(Graph&G){VNode*last;VNode*p;cout<<"请输入景点个数以及道路条数"<cin>>G.vexnum>>G.arcnum;if((G.vexnum<=0)||(G.arcnum<=0))returnfalse;G.V=(VNode*)malloc(sizeof(VNode));last=G.V;cout<<"请输入第1个景点的编号、名称、介绍"<cin>>last->sc.sno>>last->sc.sname>>last->sc.stext;last->nextArc=NULL;for(inti=1;i{p=(VNode*)malloc(sizeof(VNode));cout<<"请输入第"<cin>>p->sc.sno>>p->sc.sname>>p->sc.stext;p->nextArc=NULL;last->nextV=p;last=last->nextV;}last->nextV=NULL;charstartSno[4];charendSno[4];intlength;ArcNode*q=NULL;VNode*address=NULL;for(i=0;i{cout<<"请输入第"<cin>>startSno>>endSno>>length;address=GetAddress(startSno,G);q=(ArcNode*)malloc(sizeof(ArcNode));strcpy(q->sno,endSno);q->length=length;q->next=address->nextArc;address->nextArc=q;/*----------------无向网需正反两次-------------------*/address=GetAddress(endSno,G);q=(ArcNode*)malloc(sizeof(ArcNode));strcpy(q->sno,startSno);q->length=length;q->next=address->nextArc;address->nextArc=q;}returntrue;}//查询相关景点信息voidSearchScenery(Graph&G){intcount=0;VNode*p=G.V;charnoOrName[21];cout<<"请输入你想要查询的景点的编号或名称"<cin>>noOrName;for(inti=0;i{if(!(strcmp(noOrName,p->sc.sno)&&strcmp(noOrName,p->sc.sname))){cout<<"景点编号:"<sc.sno<cout<<"景点名称:"<sc.sname<cout<<"景点介绍:"<sc.stext<count++;break;}elsep=p->nextV;}if(!count)cout<<"查找失败!"<}//增加景点信息voidAddScenery(Graph&G){intcount=0;intflag=0;charsno[4];charsname[21];charstext[201];VNode*g=NULL;cout<<"请输入景点的编号:";cin>>sno;g=G.V;while(g){if(!strcmp(g->sc.sno,sno)){flag++;break;}elseg=g->nextV;}if(flag){cout<<"输入的景点编号重复,请重新插入!"<return;}cout<<"请输入景点的名称:";cin>>sname;cout<<"请输入景点的介绍:";cin>>stext;cout<VNode*p=G.V;VNode*parent=NULL;while(p){if(!strcmp(p->sc.sno,sno)){count++;break;}else{parent=p;p=p->nextV;}}if(!count){VNode*q;q=(VNode*)malloc(sizeof(VNode));strcpy(q->sc.sno,sno);strcpy(q->sc.sname,sname);strcpy(q->sc.stext,stext);parent->nextV=q;q->nextV=NULL;q->nextArc=NULL;G.vexnum++;cout<<"增加景点信息成功!"<}elsecout<<"增加景点编号重复,请重新增加!"<}//删除景点信息2voidDelete(char*sno1,char*sno2,Graph&G){intcount=0;VNode*address=NULL
//副菜单
voidSMenu()
cout<<"\t\t\t1)增加景点信息"<cout<<"\t\t\t2)删除景点信息"<cout<<"\t\t\t3)更新景点信息"<cout<<"\t\t\t4)增加道路信息"<cout<<"\t\t\t5)删除道路信息"<cout<<"\t\t\t6)更新道路信息"<cout<<"\t\t\t0)返回主菜单"<Start(60);}//获得ArcNode地址VNode*GetAddress(char*sno,Graph&G){VNode*p;p=G.V;for(inti=0;i{if(!strcmp(sno,p->sc.sno))returnp;elsep=p->nextV;}returnNULL;}//系统默认建图voidDirectCreate(Graph&G){G.arcnum=16;G.vexnum=10;VNode*p1;VNode*p2;ArcNode*q1;ArcNode*q2;G.V=p1=(VNode*)malloc(sizeof(VNode));strcpy(p1->sc.sno,"001");strcpy(p1->sc.sname,"艺术楼");strcpy(p1->sc.stext,"艺术");q1=(ArcNode*)malloc(sizeof(ArcNode));p1->nextArc=q1;q1->length=60;strcpy(q1->sno,"009");q2=(ArcNode*)malloc(sizeof(ArcNode));q2->length=30;strcpy(q2->sno,"008");q2->next=NULL;q1->next=q2;p2=(VNode*)malloc(sizeof(VNode));strcpy(p2->sc.sno,"002");strcpy(p2->sc.sname,"实验楼");strcpy(p2->sc.stext,"实验");p1->nextV=p2;q1=(ArcNode*)malloc(sizeof(ArcNode));strcpy(q1->sno,"009");q1->length=40;p2->nextArc=q1;q2=(ArcNode*)malloc(sizeof(ArcNode));q2->length=150;strcpy(q2->sno,"006");q1->next=q2;q2->next=NULL;p1=(VNode*)malloc(sizeof(VNode));strcpy(p1->sc.sno,"003");strcpy(p1->sc.sname,"男生宿舍");strcpy(p1->sc.stext,"住宿");p2->nextV=p1;q1=(ArcNode*)malloc(sizeof(ArcNode));q1->length=30;strcpy(q1->sno,"010");p1->nextArc=q1;q2=(ArcNode*)malloc(sizeof(ArcNode));q2->length=75;strcpy(q2->sno,"005");q1->next=q2;q2->next=NULL;p2=(VNode*)malloc(sizeof(VNode));strcpy(p2->sc.sno,"004");strcpy(p2->sc.sname,"女生宿舍");strcpy(p2->sc.stext,"住宿");p1->nextV=p2;q1=(ArcNode*)malloc(sizeof(ArcNode));q1->length=30;strcpy(q1->sno,"003");p2->nextArc=q1;q2=(ArcNode*)malloc(sizeof(ArcNode));q2->length=100;strcpy(q2->sno,"007");q1->next=q2;q2->next=NULL;p1=(VNode*)malloc(sizeof(VNode));strcpy(p1->sc.sno,"005");strcpy(p1->sc.sname,"小湖");strcpy(p1->sc.stext,"风景");p2->nextV=p1;q1=(ArcNode*)malloc(sizeof(ArcNode));q1->length=70;strcpy(q1->sno,"009");p1->nextArc=q1;q2=(ArcNode*)malloc(sizeof(ArcNode));q2->length=100;strcpy(q2->sno,"006");q1->next=q2;q1=(ArcNode*)malloc(sizeof(ArcNode));q1->length=70;strcpy(q1->sno,"008");q2->next=q1;q2=(ArcNode*)malloc(sizeof(ArcNode));q2->length=120;strcpy(q2->sno,"007");q1->next=q2;q1=(ArcNode*)malloc(sizeof(ArcNode));q1->length=60;strcpy(q1->sno,"010");q2->next=q1;q2=(ArcNode*)malloc(sizeof(ArcNode));q2->length=75;strcpy(q2->sno,"003");q1->next=q2;q2->next=NULL;p2=(VNode*)malloc(sizeof(VNode));strcpy(p2->sc.sno,"006");strcpy(p2->sc.sname,"食堂");strcpy(p2->sc.stext,"吃饭");p1->nextV=p2;q1=(ArcNode*)malloc(sizeof(ArcNode));q1->length=70;strcpy(q1->sno,"009");p2->nextArc=q1;q2=(ArcNode*)malloc(sizeof(ArcNode));q2->length=150;strcpy(q2->sno,"002");q1->next=q2;q1=(ArcNode*)malloc(sizeof(ArcNode));q1->length=100;strcpy(q1->sno,"005");q2->next=q1;q1->next=NULL;p1=(VNode*)malloc(sizeof(VNode));strcpy(p1->sc.sno,"007");strcpy(p1->sc.sname,"图书馆");strcpy(p1->sc.stext,"借书");p2->nextV=p1;q1=(ArcNode*)malloc(sizeof(ArcNode));q1->length=120;strcpy(q1->sno,"005");p1->nextArc=q1;q2=(ArcNode*)malloc(sizeof(ArcNode));q2->length=100;strcpy(q2->sno,"004");q1->next=q2;q2->next=NULL;p2=(VNode*)malloc(sizeof(VNode));strcpy(p2->sc.sno,"008");strcpy(p2->sc.sname,"篮球场");strcpy(p2->sc.stext,"运动");p1->nextV=p2;q1=(ArcNode*)malloc(sizeof(ArcNode));q1->length=70;strcpy(q1->sno,"009");p2->nextArc=q1;q2=(ArcNode*)malloc(sizeof(ArcNode));q2->length=70;strcpy(q2->sno,"005");q1->next=q2;q1=(ArcNode*)malloc(sizeof(ArcNode));q1->length=30;strcpy(q1->sno,"001");q2->next=q1;q2=(ArcNode*)malloc(sizeof(ArcNode));q2->length=20;strcpy(q2->sno,"010");q1->next=q2;q2->next=NULL;p1=(VNode*)malloc(sizeof(VNode));strcpy(p1->sc.sno,"009");strcpy(p1->sc.sname,"教学楼");strcpy(p1->sc.stext,"教学");p2->nextV=p1;q1=(ArcNode*)malloc(sizeof(ArcNode));q1->length=70;strcpy(q1->sno,"005");p1->nextArc=q1;q2=(ArcNode*)malloc(sizeof(ArcNode));q2->length=70;strcpy(q2->sno,"006");q1->next=q2;q1=(ArcNode*)malloc(sizeof(ArcNode));q1->length=40;strcpy(q1->sno,"002");q2->next=q1;q2=(ArcNode*)malloc(sizeof(ArcNode));q2->length=60;strcpy(q2->sno,"001");q1->next=q2;q1=(ArcNode*)malloc(sizeof(ArcNode));q1->length=70;strcpy(q1->sno,"008");q2->next=q1;q1->next=NULL;p2=(VNode*)malloc(sizeof(VNode));strcpy(p2->sc.sno,"010");strcpy(p2->sc.sname,"足球场");strcpy(p2->sc.stext,"运动");p1->nextV=p2;q1=(ArcNode*)malloc(sizeof(ArcNode));q1->length=20;strcpy(q1->sno,"008");p2->nextArc=q1;q2=(ArcNode*)malloc(sizeof(ArcNode));q2->length=60;strcpy(q2->sno,"005");q1->next=q2;q1=(ArcNode*)malloc(sizeof(ArcNode));q1->length=30;strcpy(q1->sno,"003");q2->next=q1;q1->next=NULL;p2->nextV=NULL;}//创建图boolCreate(Graph&G){VNode*last;VNode*p;cout<<"请输入景点个数以及道路条数"<cin>>G.vexnum>>G.arcnum;if((G.vexnum<=0)||(G.arcnum<=0))returnfalse;G.V=(VNode*)malloc(sizeof(VNode));last=G.V;cout<<"请输入第1个景点的编号、名称、介绍"<cin>>last->sc.sno>>last->sc.sname>>last->sc.stext;last->nextArc=NULL;for(inti=1;i{p=(VNode*)malloc(sizeof(VNode));cout<<"请输入第"<cin>>p->sc.sno>>p->sc.sname>>p->sc.stext;p->nextArc=NULL;last->nextV=p;last=last->nextV;}last->nextV=NULL;charstartSno[4];charendSno[4];intlength;ArcNode*q=NULL;VNode*address=NULL;for(i=0;i{cout<<"请输入第"<cin>>startSno>>endSno>>length;address=GetAddress(startSno,G);q=(ArcNode*)malloc(sizeof(ArcNode));strcpy(q->sno,endSno);q->length=length;q->next=address->nextArc;address->nextArc=q;/*----------------无向网需正反两次-------------------*/address=GetAddress(endSno,G);q=(ArcNode*)malloc(sizeof(ArcNode));strcpy(q->sno,startSno);q->length=length;q->next=address->nextArc;address->nextArc=q;}returntrue;}//查询相关景点信息voidSearchScenery(Graph&G){intcount=0;VNode*p=G.V;charnoOrName[21];cout<<"请输入你想要查询的景点的编号或名称"<cin>>noOrName;for(inti=0;i{if(!(strcmp(noOrName,p->sc.sno)&&strcmp(noOrName,p->sc.sname))){cout<<"景点编号:"<sc.sno<cout<<"景点名称:"<sc.sname<cout<<"景点介绍:"<sc.stext<count++;break;}elsep=p->nextV;}if(!count)cout<<"查找失败!"<}//增加景点信息voidAddScenery(Graph&G){intcount=0;intflag=0;charsno[4];charsname[21];charstext[201];VNode*g=NULL;cout<<"请输入景点的编号:";cin>>sno;g=G.V;while(g){if(!strcmp(g->sc.sno,sno)){flag++;break;}elseg=g->nextV;}if(flag){cout<<"输入的景点编号重复,请重新插入!"<return;}cout<<"请输入景点的名称:";cin>>sname;cout<<"请输入景点的介绍:";cin>>stext;cout<VNode*p=G.V;VNode*parent=NULL;while(p){if(!strcmp(p->sc.sno,sno)){count++;break;}else{parent=p;p=p->nextV;}}if(!count){VNode*q;q=(VNode*)malloc(sizeof(VNode));strcpy(q->sc.sno,sno);strcpy(q->sc.sname,sname);strcpy(q->sc.stext,stext);parent->nextV=q;q->nextV=NULL;q->nextArc=NULL;G.vexnum++;cout<<"增加景点信息成功!"<}elsecout<<"增加景点编号重复,请重新增加!"<}//删除景点信息2voidDelete(char*sno1,char*sno2,Graph&G){intcount=0;VNode*address=NULL
cout<<"\t\t\t2)删除景点信息"<cout<<"\t\t\t3)更新景点信息"<cout<<"\t\t\t4)增加道路信息"<cout<<"\t\t\t5)删除道路信息"<cout<<"\t\t\t6)更新道路信息"<cout<<"\t\t\t0)返回主菜单"<Start(60);}//获得ArcNode地址VNode*GetAddress(char*sno,Graph&G){VNode*p;p=G.V;for(inti=0;i{if(!strcmp(sno,p->sc.sno))returnp;elsep=p->nextV;}returnNULL;}//系统默认建图voidDirectCreate(Graph&G){G.arcnum=16;G.vexnum=10;VNode*p1;VNode*p2;ArcNode*q1;ArcNode*q2;G.V=p1=(VNode*)malloc(sizeof(VNode));strcpy(p1->sc.sno,"001");strcpy(p1->sc.sname,"艺术楼");strcpy(p1->sc.stext,"艺术");q1=(ArcNode*)malloc(sizeof(ArcNode));p1->nextArc=q1;q1->length=60;strcpy(q1->sno,"009");q2=(ArcNode*)malloc(sizeof(ArcNode));q2->length=30;strcpy(q2->sno,"008");q2->next=NULL;q1->next=q2;p2=(VNode*)malloc(sizeof(VNode));strcpy(p2->sc.sno,"002");strcpy(p2->sc.sname,"实验楼");strcpy(p2->sc.stext,"实验");p1->nextV=p2;q1=(ArcNode*)malloc(sizeof(ArcNode));strcpy(q1->sno,"009");q1->length=40;p2->nextArc=q1;q2=(ArcNode*)malloc(sizeof(ArcNode));q2->length=150;strcpy(q2->sno,"006");q1->next=q2;q2->next=NULL;p1=(VNode*)malloc(sizeof(VNode));strcpy(p1->sc.sno,"003");strcpy(p1->sc.sname,"男生宿舍");strcpy(p1->sc.stext,"住宿");p2->nextV=p1;q1=(ArcNode*)malloc(sizeof(ArcNode));q1->length=30;strcpy(q1->sno,"010");p1->nextArc=q1;q2=(ArcNode*)malloc(sizeof(ArcNode));q2->length=75;strcpy(q2->sno,"005");q1->next=q2;q2->next=NULL;p2=(VNode*)malloc(sizeof(VNode));strcpy(p2->sc.sno,"004");strcpy(p2->sc.sname,"女生宿舍");strcpy(p2->sc.stext,"住宿");p1->nextV=p2;q1=(ArcNode*)malloc(sizeof(ArcNode));q1->length=30;strcpy(q1->sno,"003");p2->nextArc=q1;q2=(ArcNode*)malloc(sizeof(ArcNode));q2->length=100;strcpy(q2->sno,"007");q1->next=q2;q2->next=NULL;p1=(VNode*)malloc(sizeof(VNode));strcpy(p1->sc.sno,"005");strcpy(p1->sc.sname,"小湖");strcpy(p1->sc.stext,"风景");p2->nextV=p1;q1=(ArcNode*)malloc(sizeof(ArcNode));q1->length=70;strcpy(q1->sno,"009");p1->nextArc=q1;q2=(ArcNode*)malloc(sizeof(ArcNode));q2->length=100;strcpy(q2->sno,"006");q1->next=q2;q1=(ArcNode*)malloc(sizeof(ArcNode));q1->length=70;strcpy(q1->sno,"008");q2->next=q1;q2=(ArcNode*)malloc(sizeof(ArcNode));q2->length=120;strcpy(q2->sno,"007");q1->next=q2;q1=(ArcNode*)malloc(sizeof(ArcNode));q1->length=60;strcpy(q1->sno,"010");q2->next=q1;q2=(ArcNode*)malloc(sizeof(ArcNode));q2->length=75;strcpy(q2->sno,"003");q1->next=q2;q2->next=NULL;p2=(VNode*)malloc(sizeof(VNode));strcpy(p2->sc.sno,"006");strcpy(p2->sc.sname,"食堂");strcpy(p2->sc.stext,"吃饭");p1->nextV=p2;q1=(ArcNode*)malloc(sizeof(ArcNode));q1->length=70;strcpy(q1->sno,"009");p2->nextArc=q1;q2=(ArcNode*)malloc(sizeof(ArcNode));q2->length=150;strcpy(q2->sno,"002");q1->next=q2;q1=(ArcNode*)malloc(sizeof(ArcNode));q1->length=100;strcpy(q1->sno,"005");q2->next=q1;q1->next=NULL;p1=(VNode*)malloc(sizeof(VNode));strcpy(p1->sc.sno,"007");strcpy(p1->sc.sname,"图书馆");strcpy(p1->sc.stext,"借书");p2->nextV=p1;q1=(ArcNode*)malloc(sizeof(ArcNode));q1->length=120;strcpy(q1->sno,"005");p1->nextArc=q1;q2=(ArcNode*)malloc(sizeof(ArcNode));q2->length=100;strcpy(q2->sno,"004");q1->next=q2;q2->next=NULL;p2=(VNode*)malloc(sizeof(VNode));strcpy(p2->sc.sno,"008");strcpy(p2->sc.sname,"篮球场");strcpy(p2->sc.stext,"运动");p1->nextV=p2;q1=(ArcNode*)malloc(sizeof(ArcNode));q1->length=70;strcpy(q1->sno,"009");p2->nextArc=q1;q2=(ArcNode*)malloc(sizeof(ArcNode));q2->length=70;strcpy(q2->sno,"005");q1->next=q2;q1=(ArcNode*)malloc(sizeof(ArcNode));q1->length=30;strcpy(q1->sno,"001");q2->next=q1;q2=(ArcNode*)malloc(sizeof(ArcNode));q2->length=20;strcpy(q2->sno,"010");q1->next=q2;q2->next=NULL;p1=(VNode*)malloc(sizeof(VNode));strcpy(p1->sc.sno,"009");strcpy(p1->sc.sname,"教学楼");strcpy(p1->sc.stext,"教学");p2->nextV=p1;q1=(ArcNode*)malloc(sizeof(ArcNode));q1->length=70;strcpy(q1->sno,"005");p1->nextArc=q1;q2=(ArcNode*)malloc(sizeof(ArcNode));q2->length=70;strcpy(q2->sno,"006");q1->next=q2;q1=(ArcNode*)malloc(sizeof(ArcNode));q1->length=40;strcpy(q1->sno,"002");q2->next=q1;q2=(ArcNode*)malloc(sizeof(ArcNode));q2->length=60;strcpy(q2->sno,"001");q1->next=q2;q1=(ArcNode*)malloc(sizeof(ArcNode));q1->length=70;strcpy(q1->sno,"008");q2->next=q1;q1->next=NULL;p2=(VNode*)malloc(sizeof(VNode));strcpy(p2->sc.sno,"010");strcpy(p2->sc.sname,"足球场");strcpy(p2->sc.stext,"运动");p1->nextV=p2;q1=(ArcNode*)malloc(sizeof(ArcNode));q1->length=20;strcpy(q1->sno,"008");p2->nextArc=q1;q2=(ArcNode*)malloc(sizeof(ArcNode));q2->length=60;strcpy(q2->sno,"005");q1->next=q2;q1=(ArcNode*)malloc(sizeof(ArcNode));q1->length=30;strcpy(q1->sno,"003");q2->next=q1;q1->next=NULL;p2->nextV=NULL;}//创建图boolCreate(Graph&G){VNode*last;VNode*p;cout<<"请输入景点个数以及道路条数"<cin>>G.vexnum>>G.arcnum;if((G.vexnum<=0)||(G.arcnum<=0))returnfalse;G.V=(VNode*)malloc(sizeof(VNode));last=G.V;cout<<"请输入第1个景点的编号、名称、介绍"<cin>>last->sc.sno>>last->sc.sname>>last->sc.stext;last->nextArc=NULL;for(inti=1;i{p=(VNode*)malloc(sizeof(VNode));cout<<"请输入第"<cin>>p->sc.sno>>p->sc.sname>>p->sc.stext;p->nextArc=NULL;last->nextV=p;last=last->nextV;}last->nextV=NULL;charstartSno[4];charendSno[4];intlength;ArcNode*q=NULL;VNode*address=NULL;for(i=0;i{cout<<"请输入第"<cin>>startSno>>endSno>>length;address=GetAddress(startSno,G);q=(ArcNode*)malloc(sizeof(ArcNode));strcpy(q->sno,endSno);q->length=length;q->next=address->nextArc;address->nextArc=q;/*----------------无向网需正反两次-------------------*/address=GetAddress(endSno,G);q=(ArcNode*)malloc(sizeof(ArcNode));strcpy(q->sno,startSno);q->length=length;q->next=address->nextArc;address->nextArc=q;}returntrue;}//查询相关景点信息voidSearchScenery(Graph&G){intcount=0;VNode*p=G.V;charnoOrName[21];cout<<"请输入你想要查询的景点的编号或名称"<cin>>noOrName;for(inti=0;i{if(!(strcmp(noOrName,p->sc.sno)&&strcmp(noOrName,p->sc.sname))){cout<<"景点编号:"<sc.sno<cout<<"景点名称:"<sc.sname<cout<<"景点介绍:"<sc.stext<count++;break;}elsep=p->nextV;}if(!count)cout<<"查找失败!"<}//增加景点信息voidAddScenery(Graph&G){intcount=0;intflag=0;charsno[4];charsname[21];charstext[201];VNode*g=NULL;cout<<"请输入景点的编号:";cin>>sno;g=G.V;while(g){if(!strcmp(g->sc.sno,sno)){flag++;break;}elseg=g->nextV;}if(flag){cout<<"输入的景点编号重复,请重新插入!"<return;}cout<<"请输入景点的名称:";cin>>sname;cout<<"请输入景点的介绍:";cin>>stext;cout<VNode*p=G.V;VNode*parent=NULL;while(p){if(!strcmp(p->sc.sno,sno)){count++;break;}else{parent=p;p=p->nextV;}}if(!count){VNode*q;q=(VNode*)malloc(sizeof(VNode));strcpy(q->sc.sno,sno);strcpy(q->sc.sname,sname);strcpy(q->sc.stext,stext);parent->nextV=q;q->nextV=NULL;q->nextArc=NULL;G.vexnum++;cout<<"增加景点信息成功!"<}elsecout<<"增加景点编号重复,请重新增加!"<}//删除景点信息2voidDelete(char*sno1,char*sno2,Graph&G){intcount=0;VNode*address=NULL
cout<<"\t\t\t3)更新景点信息"<cout<<"\t\t\t4)增加道路信息"<cout<<"\t\t\t5)删除道路信息"<cout<<"\t\t\t6)更新道路信息"<cout<<"\t\t\t0)返回主菜单"<Start(60);}//获得ArcNode地址VNode*GetAddress(char*sno,Graph&G){VNode*p;p=G.V;for(inti=0;i{if(!strcmp(sno,p->sc.sno))returnp;elsep=p->nextV;}returnNULL;}//系统默认建图voidDirectCreate(Graph&G){G.arcnum=16;G.vexnum=10;VNode*p1;VNode*p2;ArcNode*q1;ArcNode*q2;G.V=p1=(VNode*)malloc(sizeof(VNode));strcpy(p1->sc.sno,"001");strcpy(p1->sc.sname,"艺术楼");strcpy(p1->sc.stext,"艺术");q1=(ArcNode*)malloc(sizeof(ArcNode));p1->nextArc=q1;q1->length=60;strcpy(q1->sno,"009");q2=(ArcNode*)malloc(sizeof(ArcNode));q2->length=30;strcpy(q2->sno,"008");q2->next=NULL;q1->next=q2;p2=(VNode*)malloc(sizeof(VNode));strcpy(p2->sc.sno,"002");strcpy(p2->sc.sname,"实验楼");strcpy(p2->sc.stext,"实验");p1->nextV=p2;q1=(ArcNode*)malloc(sizeof(ArcNode));strcpy(q1->sno,"009");q1->length=40;p2->nextArc=q1;q2=(ArcNode*)malloc(sizeof(ArcNode));q2->length=150;strcpy(q2->sno,"006");q1->next=q2;q2->next=NULL;p1=(VNode*)malloc(sizeof(VNode));strcpy(p1->sc.sno,"003");strcpy(p1->sc.sname,"男生宿舍");strcpy(p1->sc.stext,"住宿");p2->nextV=p1;q1=(ArcNode*)malloc(sizeof(ArcNode));q1->length=30;strcpy(q1->sno,"010");p1->nextArc=q1;q2=(ArcNode*)malloc(sizeof(ArcNode));q2->length=75;strcpy(q2->sno,"005");q1->next=q2;q2->next=NULL;p2=(VNode*)malloc(sizeof(VNode));strcpy(p2->sc.sno,"004");strcpy(p2->sc.sname,"女生宿舍");strcpy(p2->sc.stext,"住宿");p1->nextV=p2;q1=(ArcNode*)malloc(sizeof(ArcNode));q1->length=30;strcpy(q1->sno,"003");p2->nextArc=q1;q2=(ArcNode*)malloc(sizeof(ArcNode));q2->length=100;strcpy(q2->sno,"007");q1->next=q2;q2->next=NULL;p1=(VNode*)malloc(sizeof(VNode));strcpy(p1->sc.sno,"005");strcpy(p1->sc.sname,"小湖");strcpy(p1->sc.stext,"风景");p2->nextV=p1;q1=(ArcNode*)malloc(sizeof(ArcNode));q1->length=70;strcpy(q1->sno,"009");p1->nextArc=q1;q2=(ArcNode*)malloc(sizeof(ArcNode));q2->length=100;strcpy(q2->sno,"006");q1->next=q2;q1=(ArcNode*)malloc(sizeof(ArcNode));q1->length=70;strcpy(q1->sno,"008");q2->next=q1;q2=(ArcNode*)malloc(sizeof(ArcNode));q2->length=120;strcpy(q2->sno,"007");q1->next=q2;q1=(ArcNode*)malloc(sizeof(ArcNode));q1->length=60;strcpy(q1->sno,"010");q2->next=q1;q2=(ArcNode*)malloc(sizeof(ArcNode));q2->length=75;strcpy(q2->sno,"003");q1->next=q2;q2->next=NULL;p2=(VNode*)malloc(sizeof(VNode));strcpy(p2->sc.sno,"006");strcpy(p2->sc.sname,"食堂");strcpy(p2->sc.stext,"吃饭");p1->nextV=p2;q1=(ArcNode*)malloc(sizeof(ArcNode));q1->length=70;strcpy(q1->sno,"009");p2->nextArc=q1;q2=(ArcNode*)malloc(sizeof(ArcNode));q2->length=150;strcpy(q2->sno,"002");q1->next=q2;q1=(ArcNode*)malloc(sizeof(ArcNode));q1->length=100;strcpy(q1->sno,"005");q2->next=q1;q1->next=NULL;p1=(VNode*)malloc(sizeof(VNode));strcpy(p1->sc.sno,"007");strcpy(p1->sc.sname,"图书馆");strcpy(p1->sc.stext,"借书");p2->nextV=p1;q1=(ArcNode*)malloc(sizeof(ArcNode));q1->length=120;strcpy(q1->sno,"005");p1->nextArc=q1;q2=(ArcNode*)malloc(sizeof(ArcNode));q2->length=100;strcpy(q2->sno,"004");q1->next=q2;q2->next=NULL;p2=(VNode*)malloc(sizeof(VNode));strcpy(p2->sc.sno,"008");strcpy(p2->sc.sname,"篮球场");strcpy(p2->sc.stext,"运动");p1->nextV=p2;q1=(ArcNode*)malloc(sizeof(ArcNode));q1->length=70;strcpy(q1->sno,"009");p2->nextArc=q1;q2=(ArcNode*)malloc(sizeof(ArcNode));q2->length=70;strcpy(q2->sno,"005");q1->next=q2;q1=(ArcNode*)malloc(sizeof(ArcNode));q1->length=30;strcpy(q1->sno,"001");q2->next=q1;q2=(ArcNode*)malloc(sizeof(ArcNode));q2->length=20;strcpy(q2->sno,"010");q1->next=q2;q2->next=NULL;p1=(VNode*)malloc(sizeof(VNode));strcpy(p1->sc.sno,"009");strcpy(p1->sc.sname,"教学楼");strcpy(p1->sc.stext,"教学");p2->nextV=p1;q1=(ArcNode*)malloc(sizeof(ArcNode));q1->length=70;strcpy(q1->sno,"005");p1->nextArc=q1;q2=(ArcNode*)malloc(sizeof(ArcNode));q2->length=70;strcpy(q2->sno,"006");q1->next=q2;q1=(ArcNode*)malloc(sizeof(ArcNode));q1->length=40;strcpy(q1->sno,"002");q2->next=q1;q2=(ArcNode*)malloc(sizeof(ArcNode));q2->length=60;strcpy(q2->sno,"001");q1->next=q2;q1=(ArcNode*)malloc(sizeof(ArcNode));q1->length=70;strcpy(q1->sno,"008");q2->next=q1;q1->next=NULL;p2=(VNode*)malloc(sizeof(VNode));strcpy(p2->sc.sno,"010");strcpy(p2->sc.sname,"足球场");strcpy(p2->sc.stext,"运动");p1->nextV=p2;q1=(ArcNode*)malloc(sizeof(ArcNode));q1->length=20;strcpy(q1->sno,"008");p2->nextArc=q1;q2=(ArcNode*)malloc(sizeof(ArcNode));q2->length=60;strcpy(q2->sno,"005");q1->next=q2;q1=(ArcNode*)malloc(sizeof(ArcNode));q1->length=30;strcpy(q1->sno,"003");q2->next=q1;q1->next=NULL;p2->nextV=NULL;}//创建图boolCreate(Graph&G){VNode*last;VNode*p;cout<<"请输入景点个数以及道路条数"<cin>>G.vexnum>>G.arcnum;if((G.vexnum<=0)||(G.arcnum<=0))returnfalse;G.V=(VNode*)malloc(sizeof(VNode));last=G.V;cout<<"请输入第1个景点的编号、名称、介绍"<cin>>last->sc.sno>>last->sc.sname>>last->sc.stext;last->nextArc=NULL;for(inti=1;i{p=(VNode*)malloc(sizeof(VNode));cout<<"请输入第"<cin>>p->sc.sno>>p->sc.sname>>p->sc.stext;p->nextArc=NULL;last->nextV=p;last=last->nextV;}last->nextV=NULL;charstartSno[4];charendSno[4];intlength;ArcNode*q=NULL;VNode*address=NULL;for(i=0;i{cout<<"请输入第"<cin>>startSno>>endSno>>length;address=GetAddress(startSno,G);q=(ArcNode*)malloc(sizeof(ArcNode));strcpy(q->sno,endSno);q->length=length;q->next=address->nextArc;address->nextArc=q;/*----------------无向网需正反两次-------------------*/address=GetAddress(endSno,G);q=(ArcNode*)malloc(sizeof(ArcNode));strcpy(q->sno,startSno);q->length=length;q->next=address->nextArc;address->nextArc=q;}returntrue;}//查询相关景点信息voidSearchScenery(Graph&G){intcount=0;VNode*p=G.V;charnoOrName[21];cout<<"请输入你想要查询的景点的编号或名称"<cin>>noOrName;for(inti=0;i{if(!(strcmp(noOrName,p->sc.sno)&&strcmp(noOrName,p->sc.sname))){cout<<"景点编号:"<sc.sno<cout<<"景点名称:"<sc.sname<cout<<"景点介绍:"<sc.stext<count++;break;}elsep=p->nextV;}if(!count)cout<<"查找失败!"<}//增加景点信息voidAddScenery(Graph&G){intcount=0;intflag=0;charsno[4];charsname[21];charstext[201];VNode*g=NULL;cout<<"请输入景点的编号:";cin>>sno;g=G.V;while(g){if(!strcmp(g->sc.sno,sno)){flag++;break;}elseg=g->nextV;}if(flag){cout<<"输入的景点编号重复,请重新插入!"<return;}cout<<"请输入景点的名称:";cin>>sname;cout<<"请输入景点的介绍:";cin>>stext;cout<VNode*p=G.V;VNode*parent=NULL;while(p){if(!strcmp(p->sc.sno,sno)){count++;break;}else{parent=p;p=p->nextV;}}if(!count){VNode*q;q=(VNode*)malloc(sizeof(VNode));strcpy(q->sc.sno,sno);strcpy(q->sc.sname,sname);strcpy(q->sc.stext,stext);parent->nextV=q;q->nextV=NULL;q->nextArc=NULL;G.vexnum++;cout<<"增加景点信息成功!"<}elsecout<<"增加景点编号重复,请重新增加!"<}//删除景点信息2voidDelete(char*sno1,char*sno2,Graph&G){intcount=0;VNode*address=NULL
cout<<"\t\t\t4)增加道路信息"<cout<<"\t\t\t5)删除道路信息"<cout<<"\t\t\t6)更新道路信息"<cout<<"\t\t\t0)返回主菜单"<Start(60);}//获得ArcNode地址VNode*GetAddress(char*sno,Graph&G){VNode*p;p=G.V;for(inti=0;i{if(!strcmp(sno,p->sc.sno))returnp;elsep=p->nextV;}returnNULL;}//系统默认建图voidDirectCreate(Graph&G){G.arcnum=16;G.vexnum=10;VNode*p1;VNode*p2;ArcNode*q1;ArcNode*q2;G.V=p1=(VNode*)malloc(sizeof(VNode));strcpy(p1->sc.sno,"001");strcpy(p1->sc.sname,"艺术楼");strcpy(p1->sc.stext,"艺术");q1=(ArcNode*)malloc(sizeof(ArcNode));p1->nextArc=q1;q1->length=60;strcpy(q1->sno,"009");q2=(ArcNode*)malloc(sizeof(ArcNode));q2->length=30;strcpy(q2->sno,"008");q2->next=NULL;q1->next=q2;p2=(VNode*)malloc(sizeof(VNode));strcpy(p2->sc.sno,"002");strcpy(p2->sc.sname,"实验楼");strcpy(p2->sc.stext,"实验");p1->nextV=p2;q1=(ArcNode*)malloc(sizeof(ArcNode));strcpy(q1->sno,"009");q1->length=40;p2->nextArc=q1;q2=(ArcNode*)malloc(sizeof(ArcNode));q2->length=150;strcpy(q2->sno,"006");q1->next=q2;q2->next=NULL;p1=(VNode*)malloc(sizeof(VNode));strcpy(p1->sc.sno,"003");strcpy(p1->sc.sname,"男生宿舍");strcpy(p1->sc.stext,"住宿");p2->nextV=p1;q1=(ArcNode*)malloc(sizeof(ArcNode));q1->length=30;strcpy(q1->sno,"010");p1->nextArc=q1;q2=(ArcNode*)malloc(sizeof(ArcNode));q2->length=75;strcpy(q2->sno,"005");q1->next=q2;q2->next=NULL;p2=(VNode*)malloc(sizeof(VNode));strcpy(p2->sc.sno,"004");strcpy(p2->sc.sname,"女生宿舍");strcpy(p2->sc.stext,"住宿");p1->nextV=p2;q1=(ArcNode*)malloc(sizeof(ArcNode));q1->length=30;strcpy(q1->sno,"003");p2->nextArc=q1;q2=(ArcNode*)malloc(sizeof(ArcNode));q2->length=100;strcpy(q2->sno,"007");q1->next=q2;q2->next=NULL;p1=(VNode*)malloc(sizeof(VNode));strcpy(p1->sc.sno,"005");strcpy(p1->sc.sname,"小湖");strcpy(p1->sc.stext,"风景");p2->nextV=p1;q1=(ArcNode*)malloc(sizeof(ArcNode));q1->length=70;strcpy(q1->sno,"009");p1->nextArc=q1;q2=(ArcNode*)malloc(sizeof(ArcNode));q2->length=100;strcpy(q2->sno,"006");q1->next=q2;q1=(ArcNode*)malloc(sizeof(ArcNode));q1->length=70;strcpy(q1->sno,"008");q2->next=q1;q2=(ArcNode*)malloc(sizeof(ArcNode));q2->length=120;strcpy(q2->sno,"007");q1->next=q2;q1=(ArcNode*)malloc(sizeof(ArcNode));q1->length=60;strcpy(q1->sno,"010");q2->next=q1;q2=(ArcNode*)malloc(sizeof(ArcNode));q2->length=75;strcpy(q2->sno,"003");q1->next=q2;q2->next=NULL;p2=(VNode*)malloc(sizeof(VNode));strcpy(p2->sc.sno,"006");strcpy(p2->sc.sname,"食堂");strcpy(p2->sc.stext,"吃饭");p1->nextV=p2;q1=(ArcNode*)malloc(sizeof(ArcNode));q1->length=70;strcpy(q1->sno,"009");p2->nextArc=q1;q2=(ArcNode*)malloc(sizeof(ArcNode));q2->length=150;strcpy(q2->sno,"002");q1->next=q2;q1=(ArcNode*)malloc(sizeof(ArcNode));q1->length=100;strcpy(q1->sno,"005");q2->next=q1;q1->next=NULL;p1=(VNode*)malloc(sizeof(VNode));strcpy(p1->sc.sno,"007");strcpy(p1->sc.sname,"图书馆");strcpy(p1->sc.stext,"借书");p2->nextV=p1;q1=(ArcNode*)malloc(sizeof(ArcNode));q1->length=120;strcpy(q1->sno,"005");p1->nextArc=q1;q2=(ArcNode*)malloc(sizeof(ArcNode));q2->length=100;strcpy(q2->sno,"004");q1->next=q2;q2->next=NULL;p2=(VNode*)malloc(sizeof(VNode));strcpy(p2->sc.sno,"008");strcpy(p2->sc.sname,"篮球场");strcpy(p2->sc.stext,"运动");p1->nextV=p2;q1=(ArcNode*)malloc(sizeof(ArcNode));q1->length=70;strcpy(q1->sno,"009");p2->nextArc=q1;q2=(ArcNode*)malloc(sizeof(ArcNode));q2->length=70;strcpy(q2->sno,"005");q1->next=q2;q1=(ArcNode*)malloc(sizeof(ArcNode));q1->length=30;strcpy(q1->sno,"001");q2->next=q1;q2=(ArcNode*)malloc(sizeof(ArcNode));q2->length=20;strcpy(q2->sno,"010");q1->next=q2;q2->next=NULL;p1=(VNode*)malloc(sizeof(VNode));strcpy(p1->sc.sno,"009");strcpy(p1->sc.sname,"教学楼");strcpy(p1->sc.stext,"教学");p2->nextV=p1;q1=(ArcNode*)malloc(sizeof(ArcNode));q1->length=70;strcpy(q1->sno,"005");p1->nextArc=q1;q2=(ArcNode*)malloc(sizeof(ArcNode));q2->length=70;strcpy(q2->sno,"006");q1->next=q2;q1=(ArcNode*)malloc(sizeof(ArcNode));q1->length=40;strcpy(q1->sno,"002");q2->next=q1;q2=(ArcNode*)malloc(sizeof(ArcNode));q2->length=60;strcpy(q2->sno,"001");q1->next=q2;q1=(ArcNode*)malloc(sizeof(ArcNode));q1->length=70;strcpy(q1->sno,"008");q2->next=q1;q1->next=NULL;p2=(VNode*)malloc(sizeof(VNode));strcpy(p2->sc.sno,"010");strcpy(p2->sc.sname,"足球场");strcpy(p2->sc.stext,"运动");p1->nextV=p2;q1=(ArcNode*)malloc(sizeof(ArcNode));q1->length=20;strcpy(q1->sno,"008");p2->nextArc=q1;q2=(ArcNode*)malloc(sizeof(ArcNode));q2->length=60;strcpy(q2->sno,"005");q1->next=q2;q1=(ArcNode*)malloc(sizeof(ArcNode));q1->length=30;strcpy(q1->sno,"003");q2->next=q1;q1->next=NULL;p2->nextV=NULL;}//创建图boolCreate(Graph&G){VNode*last;VNode*p;cout<<"请输入景点个数以及道路条数"<cin>>G.vexnum>>G.arcnum;if((G.vexnum<=0)||(G.arcnum<=0))returnfalse;G.V=(VNode*)malloc(sizeof(VNode));last=G.V;cout<<"请输入第1个景点的编号、名称、介绍"<cin>>last->sc.sno>>last->sc.sname>>last->sc.stext;last->nextArc=NULL;for(inti=1;i{p=(VNode*)malloc(sizeof(VNode));cout<<"请输入第"<cin>>p->sc.sno>>p->sc.sname>>p->sc.stext;p->nextArc=NULL;last->nextV=p;last=last->nextV;}last->nextV=NULL;charstartSno[4];charendSno[4];intlength;ArcNode*q=NULL;VNode*address=NULL;for(i=0;i{cout<<"请输入第"<cin>>startSno>>endSno>>length;address=GetAddress(startSno,G);q=(ArcNode*)malloc(sizeof(ArcNode));strcpy(q->sno,endSno);q->length=length;q->next=address->nextArc;address->nextArc=q;/*----------------无向网需正反两次-------------------*/address=GetAddress(endSno,G);q=(ArcNode*)malloc(sizeof(ArcNode));strcpy(q->sno,startSno);q->length=length;q->next=address->nextArc;address->nextArc=q;}returntrue;}//查询相关景点信息voidSearchScenery(Graph&G){intcount=0;VNode*p=G.V;charnoOrName[21];cout<<"请输入你想要查询的景点的编号或名称"<cin>>noOrName;for(inti=0;i{if(!(strcmp(noOrName,p->sc.sno)&&strcmp(noOrName,p->sc.sname))){cout<<"景点编号:"<sc.sno<cout<<"景点名称:"<sc.sname<cout<<"景点介绍:"<sc.stext<count++;break;}elsep=p->nextV;}if(!count)cout<<"查找失败!"<}//增加景点信息voidAddScenery(Graph&G){intcount=0;intflag=0;charsno[4];charsname[21];charstext[201];VNode*g=NULL;cout<<"请输入景点的编号:";cin>>sno;g=G.V;while(g){if(!strcmp(g->sc.sno,sno)){flag++;break;}elseg=g->nextV;}if(flag){cout<<"输入的景点编号重复,请重新插入!"<return;}cout<<"请输入景点的名称:";cin>>sname;cout<<"请输入景点的介绍:";cin>>stext;cout<VNode*p=G.V;VNode*parent=NULL;while(p){if(!strcmp(p->sc.sno,sno)){count++;break;}else{parent=p;p=p->nextV;}}if(!count){VNode*q;q=(VNode*)malloc(sizeof(VNode));strcpy(q->sc.sno,sno);strcpy(q->sc.sname,sname);strcpy(q->sc.stext,stext);parent->nextV=q;q->nextV=NULL;q->nextArc=NULL;G.vexnum++;cout<<"增加景点信息成功!"<}elsecout<<"增加景点编号重复,请重新增加!"<}//删除景点信息2voidDelete(char*sno1,char*sno2,Graph&G){intcount=0;VNode*address=NULL
cout<<"\t\t\t5)删除道路信息"<cout<<"\t\t\t6)更新道路信息"<cout<<"\t\t\t0)返回主菜单"<Start(60);}//获得ArcNode地址VNode*GetAddress(char*sno,Graph&G){VNode*p;p=G.V;for(inti=0;i{if(!strcmp(sno,p->sc.sno))returnp;elsep=p->nextV;}returnNULL;}//系统默认建图voidDirectCreate(Graph&G){G.arcnum=16;G.vexnum=10;VNode*p1;VNode*p2;ArcNode*q1;ArcNode*q2;G.V=p1=(VNode*)malloc(sizeof(VNode));strcpy(p1->sc.sno,"001");strcpy(p1->sc.sname,"艺术楼");strcpy(p1->sc.stext,"艺术");q1=(ArcNode*)malloc(sizeof(ArcNode));p1->nextArc=q1;q1->length=60;strcpy(q1->sno,"009");q2=(ArcNode*)malloc(sizeof(ArcNode));q2->length=30;strcpy(q2->sno,"008");q2->next=NULL;q1->next=q2;p2=(VNode*)malloc(sizeof(VNode));strcpy(p2->sc.sno,"002");strcpy(p2->sc.sname,"实验楼");strcpy(p2->sc.stext,"实验");p1->nextV=p2;q1=(ArcNode*)malloc(sizeof(ArcNode));strcpy(q1->sno,"009");q1->length=40;p2->nextArc=q1;q2=(ArcNode*)malloc(sizeof(ArcNode));q2->length=150;strcpy(q2->sno,"006");q1->next=q2;q2->next=NULL;p1=(VNode*)malloc(sizeof(VNode));strcpy(p1->sc.sno,"003");strcpy(p1->sc.sname,"男生宿舍");strcpy(p1->sc.stext,"住宿");p2->nextV=p1;q1=(ArcNode*)malloc(sizeof(ArcNode));q1->length=30;strcpy(q1->sno,"010");p1->nextArc=q1;q2=(ArcNode*)malloc(sizeof(ArcNode));q2->length=75;strcpy(q2->sno,"005");q1->next=q2;q2->next=NULL;p2=(VNode*)malloc(sizeof(VNode));strcpy(p2->sc.sno,"004");strcpy(p2->sc.sname,"女生宿舍");strcpy(p2->sc.stext,"住宿");p1->nextV=p2;q1=(ArcNode*)malloc(sizeof(ArcNode));q1->length=30;strcpy(q1->sno,"003");p2->nextArc=q1;q2=(ArcNode*)malloc(sizeof(ArcNode));q2->length=100;strcpy(q2->sno,"007");q1->next=q2;q2->next=NULL;p1=(VNode*)malloc(sizeof(VNode));strcpy(p1->sc.sno,"005");strcpy(p1->sc.sname,"小湖");strcpy(p1->sc.stext,"风景");p2->nextV=p1;q1=(ArcNode*)malloc(sizeof(ArcNode));q1->length=70;strcpy(q1->sno,"009");p1->nextArc=q1;q2=(ArcNode*)malloc(sizeof(ArcNode));q2->length=100;strcpy(q2->sno,"006");q1->next=q2;q1=(ArcNode*)malloc(sizeof(ArcNode));q1->length=70;strcpy(q1->sno,"008");q2->next=q1;q2=(ArcNode*)malloc(sizeof(ArcNode));q2->length=120;strcpy(q2->sno,"007");q1->next=q2;q1=(ArcNode*)malloc(sizeof(ArcNode));q1->length=60;strcpy(q1->sno,"010");q2->next=q1;q2=(ArcNode*)malloc(sizeof(ArcNode));q2->length=75;strcpy(q2->sno,"003");q1->next=q2;q2->next=NULL;p2=(VNode*)malloc(sizeof(VNode));strcpy(p2->sc.sno,"006");strcpy(p2->sc.sname,"食堂");strcpy(p2->sc.stext,"吃饭");p1->nextV=p2;q1=(ArcNode*)malloc(sizeof(ArcNode));q1->length=70;strcpy(q1->sno,"009");p2->nextArc=q1;q2=(ArcNode*)malloc(sizeof(ArcNode));q2->length=150;strcpy(q2->sno,"002");q1->next=q2;q1=(ArcNode*)malloc(sizeof(ArcNode));q1->length=100;strcpy(q1->sno,"005");q2->next=q1;q1->next=NULL;p1=(VNode*)malloc(sizeof(VNode));strcpy(p1->sc.sno,"007");strcpy(p1->sc.sname,"图书馆");strcpy(p1->sc.stext,"借书");p2->nextV=p1;q1=(ArcNode*)malloc(sizeof(ArcNode));q1->length=120;strcpy(q1->sno,"005");p1->nextArc=q1;q2=(ArcNode*)malloc(sizeof(ArcNode));q2->length=100;strcpy(q2->sno,"004");q1->next=q2;q2->next=NULL;p2=(VNode*)malloc(sizeof(VNode));strcpy(p2->sc.sno,"008");strcpy(p2->sc.sname,"篮球场");strcpy(p2->sc.stext,"运动");p1->nextV=p2;q1=(ArcNode*)malloc(sizeof(ArcNode));q1->length=70;strcpy(q1->sno,"009");p2->nextArc=q1;q2=(ArcNode*)malloc(sizeof(ArcNode));q2->length=70;strcpy(q2->sno,"005");q1->next=q2;q1=(ArcNode*)malloc(sizeof(ArcNode));q1->length=30;strcpy(q1->sno,"001");q2->next=q1;q2=(ArcNode*)malloc(sizeof(ArcNode));q2->length=20;strcpy(q2->sno,"010");q1->next=q2;q2->next=NULL;p1=(VNode*)malloc(sizeof(VNode));strcpy(p1->sc.sno,"009");strcpy(p1->sc.sname,"教学楼");strcpy(p1->sc.stext,"教学");p2->nextV=p1;q1=(ArcNode*)malloc(sizeof(ArcNode));q1->length=70;strcpy(q1->sno,"005");p1->nextArc=q1;q2=(ArcNode*)malloc(sizeof(ArcNode));q2->length=70;strcpy(q2->sno,"006");q1->next=q2;q1=(ArcNode*)malloc(sizeof(ArcNode));q1->length=40;strcpy(q1->sno,"002");q2->next=q1;q2=(ArcNode*)malloc(sizeof(ArcNode));q2->length=60;strcpy(q2->sno,"001");q1->next=q2;q1=(ArcNode*)malloc(sizeof(ArcNode));q1->length=70;strcpy(q1->sno,"008");q2->next=q1;q1->next=NULL;p2=(VNode*)malloc(sizeof(VNode));strcpy(p2->sc.sno,"010");strcpy(p2->sc.sname,"足球场");strcpy(p2->sc.stext,"运动");p1->nextV=p2;q1=(ArcNode*)malloc(sizeof(ArcNode));q1->length=20;strcpy(q1->sno,"008");p2->nextArc=q1;q2=(ArcNode*)malloc(sizeof(ArcNode));q2->length=60;strcpy(q2->sno,"005");q1->next=q2;q1=(ArcNode*)malloc(sizeof(ArcNode));q1->length=30;strcpy(q1->sno,"003");q2->next=q1;q1->next=NULL;p2->nextV=NULL;}//创建图boolCreate(Graph&G){VNode*last;VNode*p;cout<<"请输入景点个数以及道路条数"<cin>>G.vexnum>>G.arcnum;if((G.vexnum<=0)||(G.arcnum<=0))returnfalse;G.V=(VNode*)malloc(sizeof(VNode));last=G.V;cout<<"请输入第1个景点的编号、名称、介绍"<cin>>last->sc.sno>>last->sc.sname>>last->sc.stext;last->nextArc=NULL;for(inti=1;i{p=(VNode*)malloc(sizeof(VNode));cout<<"请输入第"<cin>>p->sc.sno>>p->sc.sname>>p->sc.stext;p->nextArc=NULL;last->nextV=p;last=last->nextV;}last->nextV=NULL;charstartSno[4];charendSno[4];intlength;ArcNode*q=NULL;VNode*address=NULL;for(i=0;i{cout<<"请输入第"<cin>>startSno>>endSno>>length;address=GetAddress(startSno,G);q=(ArcNode*)malloc(sizeof(ArcNode));strcpy(q->sno,endSno);q->length=length;q->next=address->nextArc;address->nextArc=q;/*----------------无向网需正反两次-------------------*/address=GetAddress(endSno,G);q=(ArcNode*)malloc(sizeof(ArcNode));strcpy(q->sno,startSno);q->length=length;q->next=address->nextArc;address->nextArc=q;}returntrue;}//查询相关景点信息voidSearchScenery(Graph&G){intcount=0;VNode*p=G.V;charnoOrName[21];cout<<"请输入你想要查询的景点的编号或名称"<cin>>noOrName;for(inti=0;i{if(!(strcmp(noOrName,p->sc.sno)&&strcmp(noOrName,p->sc.sname))){cout<<"景点编号:"<sc.sno<cout<<"景点名称:"<sc.sname<cout<<"景点介绍:"<sc.stext<count++;break;}elsep=p->nextV;}if(!count)cout<<"查找失败!"<}//增加景点信息voidAddScenery(Graph&G){intcount=0;intflag=0;charsno[4];charsname[21];charstext[201];VNode*g=NULL;cout<<"请输入景点的编号:";cin>>sno;g=G.V;while(g){if(!strcmp(g->sc.sno,sno)){flag++;break;}elseg=g->nextV;}if(flag){cout<<"输入的景点编号重复,请重新插入!"<return;}cout<<"请输入景点的名称:";cin>>sname;cout<<"请输入景点的介绍:";cin>>stext;cout<VNode*p=G.V;VNode*parent=NULL;while(p){if(!strcmp(p->sc.sno,sno)){count++;break;}else{parent=p;p=p->nextV;}}if(!count){VNode*q;q=(VNode*)malloc(sizeof(VNode));strcpy(q->sc.sno,sno);strcpy(q->sc.sname,sname);strcpy(q->sc.stext,stext);parent->nextV=q;q->nextV=NULL;q->nextArc=NULL;G.vexnum++;cout<<"增加景点信息成功!"<}elsecout<<"增加景点编号重复,请重新增加!"<}//删除景点信息2voidDelete(char*sno1,char*sno2,Graph&G){intcount=0;VNode*address=NULL
cout<<"\t\t\t6)更新道路信息"<cout<<"\t\t\t0)返回主菜单"<Start(60);}//获得ArcNode地址VNode*GetAddress(char*sno,Graph&G){VNode*p;p=G.V;for(inti=0;i{if(!strcmp(sno,p->sc.sno))returnp;elsep=p->nextV;}returnNULL;}//系统默认建图voidDirectCreate(Graph&G){G.arcnum=16;G.vexnum=10;VNode*p1;VNode*p2;ArcNode*q1;ArcNode*q2;G.V=p1=(VNode*)malloc(sizeof(VNode));strcpy(p1->sc.sno,"001");strcpy(p1->sc.sname,"艺术楼");strcpy(p1->sc.stext,"艺术");q1=(ArcNode*)malloc(sizeof(ArcNode));p1->nextArc=q1;q1->length=60;strcpy(q1->sno,"009");q2=(ArcNode*)malloc(sizeof(ArcNode));q2->length=30;strcpy(q2->sno,"008");q2->next=NULL;q1->next=q2;p2=(VNode*)malloc(sizeof(VNode));strcpy(p2->sc.sno,"002");strcpy(p2->sc.sname,"实验楼");strcpy(p2->sc.stext,"实验");p1->nextV=p2;q1=(ArcNode*)malloc(sizeof(ArcNode));strcpy(q1->sno,"009");q1->length=40;p2->nextArc=q1;q2=(ArcNode*)malloc(sizeof(ArcNode));q2->length=150;strcpy(q2->sno,"006");q1->next=q2;q2->next=NULL;p1=(VNode*)malloc(sizeof(VNode));strcpy(p1->sc.sno,"003");strcpy(p1->sc.sname,"男生宿舍");strcpy(p1->sc.stext,"住宿");p2->nextV=p1;q1=(ArcNode*)malloc(sizeof(ArcNode));q1->length=30;strcpy(q1->sno,"010");p1->nextArc=q1;q2=(ArcNode*)malloc(sizeof(ArcNode));q2->length=75;strcpy(q2->sno,"005");q1->next=q2;q2->next=NULL;p2=(VNode*)malloc(sizeof(VNode));strcpy(p2->sc.sno,"004");strcpy(p2->sc.sname,"女生宿舍");strcpy(p2->sc.stext,"住宿");p1->nextV=p2;q1=(ArcNode*)malloc(sizeof(ArcNode));q1->length=30;strcpy(q1->sno,"003");p2->nextArc=q1;q2=(ArcNode*)malloc(sizeof(ArcNode));q2->length=100;strcpy(q2->sno,"007");q1->next=q2;q2->next=NULL;p1=(VNode*)malloc(sizeof(VNode));strcpy(p1->sc.sno,"005");strcpy(p1->sc.sname,"小湖");strcpy(p1->sc.stext,"风景");p2->nextV=p1;q1=(ArcNode*)malloc(sizeof(ArcNode));q1->length=70;strcpy(q1->sno,"009");p1->nextArc=q1;q2=(ArcNode*)malloc(sizeof(ArcNode));q2->length=100;strcpy(q2->sno,"006");q1->next=q2;q1=(ArcNode*)malloc(sizeof(ArcNode));q1->length=70;strcpy(q1->sno,"008");q2->next=q1;q2=(ArcNode*)malloc(sizeof(ArcNode));q2->length=120;strcpy(q2->sno,"007");q1->next=q2;q1=(ArcNode*)malloc(sizeof(ArcNode));q1->length=60;strcpy(q1->sno,"010");q2->next=q1;q2=(ArcNode*)malloc(sizeof(ArcNode));q2->length=75;strcpy(q2->sno,"003");q1->next=q2;q2->next=NULL;p2=(VNode*)malloc(sizeof(VNode));strcpy(p2->sc.sno,"006");strcpy(p2->sc.sname,"食堂");strcpy(p2->sc.stext,"吃饭");p1->nextV=p2;q1=(ArcNode*)malloc(sizeof(ArcNode));q1->length=70;strcpy(q1->sno,"009");p2->nextArc=q1;q2=(ArcNode*)malloc(sizeof(ArcNode));q2->length=150;strcpy(q2->sno,"002");q1->next=q2;q1=(ArcNode*)malloc(sizeof(ArcNode));q1->length=100;strcpy(q1->sno,"005");q2->next=q1;q1->next=NULL;p1=(VNode*)malloc(sizeof(VNode));strcpy(p1->sc.sno,"007");strcpy(p1->sc.sname,"图书馆");strcpy(p1->sc.stext,"借书");p2->nextV=p1;q1=(ArcNode*)malloc(sizeof(ArcNode));q1->length=120;strcpy(q1->sno,"005");p1->nextArc=q1;q2=(ArcNode*)malloc(sizeof(ArcNode));q2->length=100;strcpy(q2->sno,"004");q1->next=q2;q2->next=NULL;p2=(VNode*)malloc(sizeof(VNode));strcpy(p2->sc.sno,"008");strcpy(p2->sc.sname,"篮球场");strcpy(p2->sc.stext,"运动");p1->nextV=p2;q1=(ArcNode*)malloc(sizeof(ArcNode));q1->length=70;strcpy(q1->sno,"009");p2->nextArc=q1;q2=(ArcNode*)malloc(sizeof(ArcNode));q2->length=70;strcpy(q2->sno,"005");q1->next=q2;q1=(ArcNode*)malloc(sizeof(ArcNode));q1->length=30;strcpy(q1->sno,"001");q2->next=q1;q2=(ArcNode*)malloc(sizeof(ArcNode));q2->length=20;strcpy(q2->sno,"010");q1->next=q2;q2->next=NULL;p1=(VNode*)malloc(sizeof(VNode));strcpy(p1->sc.sno,"009");strcpy(p1->sc.sname,"教学楼");strcpy(p1->sc.stext,"教学");p2->nextV=p1;q1=(ArcNode*)malloc(sizeof(ArcNode));q1->length=70;strcpy(q1->sno,"005");p1->nextArc=q1;q2=(ArcNode*)malloc(sizeof(ArcNode));q2->length=70;strcpy(q2->sno,"006");q1->next=q2;q1=(ArcNode*)malloc(sizeof(ArcNode));q1->length=40;strcpy(q1->sno,"002");q2->next=q1;q2=(ArcNode*)malloc(sizeof(ArcNode));q2->length=60;strcpy(q2->sno,"001");q1->next=q2;q1=(ArcNode*)malloc(sizeof(ArcNode));q1->length=70;strcpy(q1->sno,"008");q2->next=q1;q1->next=NULL;p2=(VNode*)malloc(sizeof(VNode));strcpy(p2->sc.sno,"010");strcpy(p2->sc.sname,"足球场");strcpy(p2->sc.stext,"运动");p1->nextV=p2;q1=(ArcNode*)malloc(sizeof(ArcNode));q1->length=20;strcpy(q1->sno,"008");p2->nextArc=q1;q2=(ArcNode*)malloc(sizeof(ArcNode));q2->length=60;strcpy(q2->sno,"005");q1->next=q2;q1=(ArcNode*)malloc(sizeof(ArcNode));q1->length=30;strcpy(q1->sno,"003");q2->next=q1;q1->next=NULL;p2->nextV=NULL;}//创建图boolCreate(Graph&G){VNode*last;VNode*p;cout<<"请输入景点个数以及道路条数"<cin>>G.vexnum>>G.arcnum;if((G.vexnum<=0)||(G.arcnum<=0))returnfalse;G.V=(VNode*)malloc(sizeof(VNode));last=G.V;cout<<"请输入第1个景点的编号、名称、介绍"<cin>>last->sc.sno>>last->sc.sname>>last->sc.stext;last->nextArc=NULL;for(inti=1;i{p=(VNode*)malloc(sizeof(VNode));cout<<"请输入第"<cin>>p->sc.sno>>p->sc.sname>>p->sc.stext;p->nextArc=NULL;last->nextV=p;last=last->nextV;}last->nextV=NULL;charstartSno[4];charendSno[4];intlength;ArcNode*q=NULL;VNode*address=NULL;for(i=0;i{cout<<"请输入第"<cin>>startSno>>endSno>>length;address=GetAddress(startSno,G);q=(ArcNode*)malloc(sizeof(ArcNode));strcpy(q->sno,endSno);q->length=length;q->next=address->nextArc;address->nextArc=q;/*----------------无向网需正反两次-------------------*/address=GetAddress(endSno,G);q=(ArcNode*)malloc(sizeof(ArcNode));strcpy(q->sno,startSno);q->length=length;q->next=address->nextArc;address->nextArc=q;}returntrue;}//查询相关景点信息voidSearchScenery(Graph&G){intcount=0;VNode*p=G.V;charnoOrName[21];cout<<"请输入你想要查询的景点的编号或名称"<cin>>noOrName;for(inti=0;i{if(!(strcmp(noOrName,p->sc.sno)&&strcmp(noOrName,p->sc.sname))){cout<<"景点编号:"<sc.sno<cout<<"景点名称:"<sc.sname<cout<<"景点介绍:"<sc.stext<count++;break;}elsep=p->nextV;}if(!count)cout<<"查找失败!"<}//增加景点信息voidAddScenery(Graph&G){intcount=0;intflag=0;charsno[4];charsname[21];charstext[201];VNode*g=NULL;cout<<"请输入景点的编号:";cin>>sno;g=G.V;while(g){if(!strcmp(g->sc.sno,sno)){flag++;break;}elseg=g->nextV;}if(flag){cout<<"输入的景点编号重复,请重新插入!"<return;}cout<<"请输入景点的名称:";cin>>sname;cout<<"请输入景点的介绍:";cin>>stext;cout<VNode*p=G.V;VNode*parent=NULL;while(p){if(!strcmp(p->sc.sno,sno)){count++;break;}else{parent=p;p=p->nextV;}}if(!count){VNode*q;q=(VNode*)malloc(sizeof(VNode));strcpy(q->sc.sno,sno);strcpy(q->sc.sname,sname);strcpy(q->sc.stext,stext);parent->nextV=q;q->nextV=NULL;q->nextArc=NULL;G.vexnum++;cout<<"增加景点信息成功!"<}elsecout<<"增加景点编号重复,请重新增加!"<}//删除景点信息2voidDelete(char*sno1,char*sno2,Graph&G){intcount=0;VNode*address=NULL
cout<<"\t\t\t0)返回主菜单"<Start(60);}//获得ArcNode地址VNode*GetAddress(char*sno,Graph&G){VNode*p;p=G.V;for(inti=0;i{if(!strcmp(sno,p->sc.sno))returnp;elsep=p->nextV;}returnNULL;}//系统默认建图voidDirectCreate(Graph&G){G.arcnum=16;G.vexnum=10;VNode*p1;VNode*p2;ArcNode*q1;ArcNode*q2;G.V=p1=(VNode*)malloc(sizeof(VNode));strcpy(p1->sc.sno,"001");strcpy(p1->sc.sname,"艺术楼");strcpy(p1->sc.stext,"艺术");q1=(ArcNode*)malloc(sizeof(ArcNode));p1->nextArc=q1;q1->length=60;strcpy(q1->sno,"009");q2=(ArcNode*)malloc(sizeof(ArcNode));q2->length=30;strcpy(q2->sno,"008");q2->next=NULL;q1->next=q2;p2=(VNode*)malloc(sizeof(VNode));strcpy(p2->sc.sno,"002");strcpy(p2->sc.sname,"实验楼");strcpy(p2->sc.stext,"实验");p1->nextV=p2;q1=(ArcNode*)malloc(sizeof(ArcNode));strcpy(q1->sno,"009");q1->length=40;p2->nextArc=q1;q2=(ArcNode*)malloc(sizeof(ArcNode));q2->length=150;strcpy(q2->sno,"006");q1->next=q2;q2->next=NULL;p1=(VNode*)malloc(sizeof(VNode));strcpy(p1->sc.sno,"003");strcpy(p1->sc.sname,"男生宿舍");strcpy(p1->sc.stext,"住宿");p2->nextV=p1;q1=(ArcNode*)malloc(sizeof(ArcNode));q1->length=30;strcpy(q1->sno,"010");p1->nextArc=q1;q2=(ArcNode*)malloc(sizeof(ArcNode));q2->length=75;strcpy(q2->sno,"005");q1->next=q2;q2->next=NULL;p2=(VNode*)malloc(sizeof(VNode));strcpy(p2->sc.sno,"004");strcpy(p2->sc.sname,"女生宿舍");strcpy(p2->sc.stext,"住宿");p1->nextV=p2;q1=(ArcNode*)malloc(sizeof(ArcNode));q1->length=30;strcpy(q1->sno,"003");p2->nextArc=q1;q2=(ArcNode*)malloc(sizeof(ArcNode));q2->length=100;strcpy(q2->sno,"007");q1->next=q2;q2->next=NULL;p1=(VNode*)malloc(sizeof(VNode));strcpy(p1->sc.sno,"005");strcpy(p1->sc.sname,"小湖");strcpy(p1->sc.stext,"风景");p2->nextV=p1;q1=(ArcNode*)malloc(sizeof(ArcNode));q1->length=70;strcpy(q1->sno,"009");p1->nextArc=q1;q2=(ArcNode*)malloc(sizeof(ArcNode));q2->length=100;strcpy(q2->sno,"006");q1->next=q2;q1=(ArcNode*)malloc(sizeof(ArcNode));q1->length=70;strcpy(q1->sno,"008");q2->next=q1;q2=(ArcNode*)malloc(sizeof(ArcNode));q2->length=120;strcpy(q2->sno,"007");q1->next=q2;q1=(ArcNode*)malloc(sizeof(ArcNode));q1->length=60;strcpy(q1->sno,"010");q2->next=q1;q2=(ArcNode*)malloc(sizeof(ArcNode));q2->length=75;strcpy(q2->sno,"003");q1->next=q2;q2->next=NULL;p2=(VNode*)malloc(sizeof(VNode));strcpy(p2->sc.sno,"006");strcpy(p2->sc.sname,"食堂");strcpy(p2->sc.stext,"吃饭");p1->nextV=p2;q1=(ArcNode*)malloc(sizeof(ArcNode));q1->length=70;strcpy(q1->sno,"009");p2->nextArc=q1;q2=(ArcNode*)malloc(sizeof(ArcNode));q2->length=150;strcpy(q2->sno,"002");q1->next=q2;q1=(ArcNode*)malloc(sizeof(ArcNode));q1->length=100;strcpy(q1->sno,"005");q2->next=q1;q1->next=NULL;p1=(VNode*)malloc(sizeof(VNode));strcpy(p1->sc.sno,"007");strcpy(p1->sc.sname,"图书馆");strcpy(p1->sc.stext,"借书");p2->nextV=p1;q1=(ArcNode*)malloc(sizeof(ArcNode));q1->length=120;strcpy(q1->sno,"005");p1->nextArc=q1;q2=(ArcNode*)malloc(sizeof(ArcNode));q2->length=100;strcpy(q2->sno,"004");q1->next=q2;q2->next=NULL;p2=(VNode*)malloc(sizeof(VNode));strcpy(p2->sc.sno,"008");strcpy(p2->sc.sname,"篮球场");strcpy(p2->sc.stext,"运动");p1->nextV=p2;q1=(ArcNode*)malloc(sizeof(ArcNode));q1->length=70;strcpy(q1->sno,"009");p2->nextArc=q1;q2=(ArcNode*)malloc(sizeof(ArcNode));q2->length=70;strcpy(q2->sno,"005");q1->next=q2;q1=(ArcNode*)malloc(sizeof(ArcNode));q1->length=30;strcpy(q1->sno,"001");q2->next=q1;q2=(ArcNode*)malloc(sizeof(ArcNode));q2->length=20;strcpy(q2->sno,"010");q1->next=q2;q2->next=NULL;p1=(VNode*)malloc(sizeof(VNode));strcpy(p1->sc.sno,"009");strcpy(p1->sc.sname,"教学楼");strcpy(p1->sc.stext,"教学");p2->nextV=p1;q1=(ArcNode*)malloc(sizeof(ArcNode));q1->length=70;strcpy(q1->sno,"005");p1->nextArc=q1;q2=(ArcNode*)malloc(sizeof(ArcNode));q2->length=70;strcpy(q2->sno,"006");q1->next=q2;q1=(ArcNode*)malloc(sizeof(ArcNode));q1->length=40;strcpy(q1->sno,"002");q2->next=q1;q2=(ArcNode*)malloc(sizeof(ArcNode));q2->length=60;strcpy(q2->sno,"001");q1->next=q2;q1=(ArcNode*)malloc(sizeof(ArcNode));q1->length=70;strcpy(q1->sno,"008");q2->next=q1;q1->next=NULL;p2=(VNode*)malloc(sizeof(VNode));strcpy(p2->sc.sno,"010");strcpy(p2->sc.sname,"足球场");strcpy(p2->sc.stext,"运动");p1->nextV=p2;q1=(ArcNode*)malloc(sizeof(ArcNode));q1->length=20;strcpy(q1->sno,"008");p2->nextArc=q1;q2=(ArcNode*)malloc(sizeof(ArcNode));q2->length=60;strcpy(q2->sno,"005");q1->next=q2;q1=(ArcNode*)malloc(sizeof(ArcNode));q1->length=30;strcpy(q1->sno,"003");q2->next=q1;q1->next=NULL;p2->nextV=NULL;}//创建图boolCreate(Graph&G){VNode*last;VNode*p;cout<<"请输入景点个数以及道路条数"<cin>>G.vexnum>>G.arcnum;if((G.vexnum<=0)||(G.arcnum<=0))returnfalse;G.V=(VNode*)malloc(sizeof(VNode));last=G.V;cout<<"请输入第1个景点的编号、名称、介绍"<cin>>last->sc.sno>>last->sc.sname>>last->sc.stext;last->nextArc=NULL;for(inti=1;i{p=(VNode*)malloc(sizeof(VNode));cout<<"请输入第"<cin>>p->sc.sno>>p->sc.sname>>p->sc.stext;p->nextArc=NULL;last->nextV=p;last=last->nextV;}last->nextV=NULL;charstartSno[4];charendSno[4];intlength;ArcNode*q=NULL;VNode*address=NULL;for(i=0;i{cout<<"请输入第"<cin>>startSno>>endSno>>length;address=GetAddress(startSno,G);q=(ArcNode*)malloc(sizeof(ArcNode));strcpy(q->sno,endSno);q->length=length;q->next=address->nextArc;address->nextArc=q;/*----------------无向网需正反两次-------------------*/address=GetAddress(endSno,G);q=(ArcNode*)malloc(sizeof(ArcNode));strcpy(q->sno,startSno);q->length=length;q->next=address->nextArc;address->nextArc=q;}returntrue;}//查询相关景点信息voidSearchScenery(Graph&G){intcount=0;VNode*p=G.V;charnoOrName[21];cout<<"请输入你想要查询的景点的编号或名称"<cin>>noOrName;for(inti=0;i{if(!(strcmp(noOrName,p->sc.sno)&&strcmp(noOrName,p->sc.sname))){cout<<"景点编号:"<sc.sno<cout<<"景点名称:"<sc.sname<cout<<"景点介绍:"<sc.stext<count++;break;}elsep=p->nextV;}if(!count)cout<<"查找失败!"<}//增加景点信息voidAddScenery(Graph&G){intcount=0;intflag=0;charsno[4];charsname[21];charstext[201];VNode*g=NULL;cout<<"请输入景点的编号:";cin>>sno;g=G.V;while(g){if(!strcmp(g->sc.sno,sno)){flag++;break;}elseg=g->nextV;}if(flag){cout<<"输入的景点编号重复,请重新插入!"<return;}cout<<"请输入景点的名称:";cin>>sname;cout<<"请输入景点的介绍:";cin>>stext;cout<VNode*p=G.V;VNode*parent=NULL;while(p){if(!strcmp(p->sc.sno,sno)){count++;break;}else{parent=p;p=p->nextV;}}if(!count){VNode*q;q=(VNode*)malloc(sizeof(VNode));strcpy(q->sc.sno,sno);strcpy(q->sc.sname,sname);strcpy(q->sc.stext,stext);parent->nextV=q;q->nextV=NULL;q->nextArc=NULL;G.vexnum++;cout<<"增加景点信息成功!"<}elsecout<<"增加景点编号重复,请重新增加!"<}//删除景点信息2voidDelete(char*sno1,char*sno2,Graph&G){intcount=0;VNode*address=NULL
//获得ArcNode地址
VNode*GetAddress(char*sno,Graph&G)
VNode*p;
p=G.V;
for(inti=0;i{if(!strcmp(sno,p->sc.sno))returnp;elsep=p->nextV;}returnNULL;}//系统默认建图voidDirectCreate(Graph&G){G.arcnum=16;G.vexnum=10;VNode*p1;VNode*p2;ArcNode*q1;ArcNode*q2;G.V=p1=(VNode*)malloc(sizeof(VNode));strcpy(p1->sc.sno,"001");strcpy(p1->sc.sname,"艺术楼");strcpy(p1->sc.stext,"艺术");q1=(ArcNode*)malloc(sizeof(ArcNode));p1->nextArc=q1;q1->length=60;strcpy(q1->sno,"009");q2=(ArcNode*)malloc(sizeof(ArcNode));q2->length=30;strcpy(q2->sno,"008");q2->next=NULL;q1->next=q2;p2=(VNode*)malloc(sizeof(VNode));strcpy(p2->sc.sno,"002");strcpy(p2->sc.sname,"实验楼");strcpy(p2->sc.stext,"实验");p1->nextV=p2;q1=(ArcNode*)malloc(sizeof(ArcNode));strcpy(q1->sno,"009");q1->length=40;p2->nextArc=q1;q2=(ArcNode*)malloc(sizeof(ArcNode));q2->length=150;strcpy(q2->sno,"006");q1->next=q2;q2->next=NULL;p1=(VNode*)malloc(sizeof(VNode));strcpy(p1->sc.sno,"003");strcpy(p1->sc.sname,"男生宿舍");strcpy(p1->sc.stext,"住宿");p2->nextV=p1;q1=(ArcNode*)malloc(sizeof(ArcNode));q1->length=30;strcpy(q1->sno,"010");p1->nextArc=q1;q2=(ArcNode*)malloc(sizeof(ArcNode));q2->length=75;strcpy(q2->sno,"005");q1->next=q2;q2->next=NULL;p2=(VNode*)malloc(sizeof(VNode));strcpy(p2->sc.sno,"004");strcpy(p2->sc.sname,"女生宿舍");strcpy(p2->sc.stext,"住宿");p1->nextV=p2;q1=(ArcNode*)malloc(sizeof(ArcNode));q1->length=30;strcpy(q1->sno,"003");p2->nextArc=q1;q2=(ArcNode*)malloc(sizeof(ArcNode));q2->length=100;strcpy(q2->sno,"007");q1->next=q2;q2->next=NULL;p1=(VNode*)malloc(sizeof(VNode));strcpy(p1->sc.sno,"005");strcpy(p1->sc.sname,"小湖");strcpy(p1->sc.stext,"风景");p2->nextV=p1;q1=(ArcNode*)malloc(sizeof(ArcNode));q1->length=70;strcpy(q1->sno,"009");p1->nextArc=q1;q2=(ArcNode*)malloc(sizeof(ArcNode));q2->length=100;strcpy(q2->sno,"006");q1->next=q2;q1=(ArcNode*)malloc(sizeof(ArcNode));q1->length=70;strcpy(q1->sno,"008");q2->next=q1;q2=(ArcNode*)malloc(sizeof(ArcNode));q2->length=120;strcpy(q2->sno,"007");q1->next=q2;q1=(ArcNode*)malloc(sizeof(ArcNode));q1->length=60;strcpy(q1->sno,"010");q2->next=q1;q2=(ArcNode*)malloc(sizeof(ArcNode));q2->length=75;strcpy(q2->sno,"003");q1->next=q2;q2->next=NULL;p2=(VNode*)malloc(sizeof(VNode));strcpy(p2->sc.sno,"006");strcpy(p2->sc.sname,"食堂");strcpy(p2->sc.stext,"吃饭");p1->nextV=p2;q1=(ArcNode*)malloc(sizeof(ArcNode));q1->length=70;strcpy(q1->sno,"009");p2->nextArc=q1;q2=(ArcNode*)malloc(sizeof(ArcNode));q2->length=150;strcpy(q2->sno,"002");q1->next=q2;q1=(ArcNode*)malloc(sizeof(ArcNode));q1->length=100;strcpy(q1->sno,"005");q2->next=q1;q1->next=NULL;p1=(VNode*)malloc(sizeof(VNode));strcpy(p1->sc.sno,"007");strcpy(p1->sc.sname,"图书馆");strcpy(p1->sc.stext,"借书");p2->nextV=p1;q1=(ArcNode*)malloc(sizeof(ArcNode));q1->length=120;strcpy(q1->sno,"005");p1->nextArc=q1;q2=(ArcNode*)malloc(sizeof(ArcNode));q2->length=100;strcpy(q2->sno,"004");q1->next=q2;q2->next=NULL;p2=(VNode*)malloc(sizeof(VNode));strcpy(p2->sc.sno,"008");strcpy(p2->sc.sname,"篮球场");strcpy(p2->sc.stext,"运动");p1->nextV=p2;q1=(ArcNode*)malloc(sizeof(ArcNode));q1->length=70;strcpy(q1->sno,"009");p2->nextArc=q1;q2=(ArcNode*)malloc(sizeof(ArcNode));q2->length=70;strcpy(q2->sno,"005");q1->next=q2;q1=(ArcNode*)malloc(sizeof(ArcNode));q1->length=30;strcpy(q1->sno,"001");q2->next=q1;q2=(ArcNode*)malloc(sizeof(ArcNode));q2->length=20;strcpy(q2->sno,"010");q1->next=q2;q2->next=NULL;p1=(VNode*)malloc(sizeof(VNode));strcpy(p1->sc.sno,"009");strcpy(p1->sc.sname,"教学楼");strcpy(p1->sc.stext,"教学");p2->nextV=p1;q1=(ArcNode*)malloc(sizeof(ArcNode));q1->length=70;strcpy(q1->sno,"005");p1->nextArc=q1;q2=(ArcNode*)malloc(sizeof(ArcNode));q2->length=70;strcpy(q2->sno,"006");q1->next=q2;q1=(ArcNode*)malloc(sizeof(ArcNode));q1->length=40;strcpy(q1->sno,"002");q2->next=q1;q2=(ArcNode*)malloc(sizeof(ArcNode));q2->length=60;strcpy(q2->sno,"001");q1->next=q2;q1=(ArcNode*)malloc(sizeof(ArcNode));q1->length=70;strcpy(q1->sno,"008");q2->next=q1;q1->next=NULL;p2=(VNode*)malloc(sizeof(VNode));strcpy(p2->sc.sno,"010");strcpy(p2->sc.sname,"足球场");strcpy(p2->sc.stext,"运动");p1->nextV=p2;q1=(ArcNode*)malloc(sizeof(ArcNode));q1->length=20;strcpy(q1->sno,"008");p2->nextArc=q1;q2=(ArcNode*)malloc(sizeof(ArcNode));q2->length=60;strcpy(q2->sno,"005");q1->next=q2;q1=(ArcNode*)malloc(sizeof(ArcNode));q1->length=30;strcpy(q1->sno,"003");q2->next=q1;q1->next=NULL;p2->nextV=NULL;}//创建图boolCreate(Graph&G){VNode*last;VNode*p;cout<<"请输入景点个数以及道路条数"<cin>>G.vexnum>>G.arcnum;if((G.vexnum<=0)||(G.arcnum<=0))returnfalse;G.V=(VNode*)malloc(sizeof(VNode));last=G.V;cout<<"请输入第1个景点的编号、名称、介绍"<cin>>last->sc.sno>>last->sc.sname>>last->sc.stext;last->nextArc=NULL;for(inti=1;i{p=(VNode*)malloc(sizeof(VNode));cout<<"请输入第"<cin>>p->sc.sno>>p->sc.sname>>p->sc.stext;p->nextArc=NULL;last->nextV=p;last=last->nextV;}last->nextV=NULL;charstartSno[4];charendSno[4];intlength;ArcNode*q=NULL;VNode*address=NULL;for(i=0;i{cout<<"请输入第"<cin>>startSno>>endSno>>length;address=GetAddress(startSno,G);q=(ArcNode*)malloc(sizeof(ArcNode));strcpy(q->sno,endSno);q->length=length;q->next=address->nextArc;address->nextArc=q;/*----------------无向网需正反两次-------------------*/address=GetAddress(endSno,G);q=(ArcNode*)malloc(sizeof(ArcNode));strcpy(q->sno,startSno);q->length=length;q->next=address->nextArc;address->nextArc=q;}returntrue;}//查询相关景点信息voidSearchScenery(Graph&G){intcount=0;VNode*p=G.V;charnoOrName[21];cout<<"请输入你想要查询的景点的编号或名称"<cin>>noOrName;for(inti=0;i{if(!(strcmp(noOrName,p->sc.sno)&&strcmp(noOrName,p->sc.sname))){cout<<"景点编号:"<sc.sno<cout<<"景点名称:"<sc.sname<cout<<"景点介绍:"<sc.stext<count++;break;}elsep=p->nextV;}if(!count)cout<<"查找失败!"<}//增加景点信息voidAddScenery(Graph&G){intcount=0;intflag=0;charsno[4];charsname[21];charstext[201];VNode*g=NULL;cout<<"请输入景点的编号:";cin>>sno;g=G.V;while(g){if(!strcmp(g->sc.sno,sno)){flag++;break;}elseg=g->nextV;}if(flag){cout<<"输入的景点编号重复,请重新插入!"<return;}cout<<"请输入景点的名称:";cin>>sname;cout<<"请输入景点的介绍:";cin>>stext;cout<VNode*p=G.V;VNode*parent=NULL;while(p){if(!strcmp(p->sc.sno,sno)){count++;break;}else{parent=p;p=p->nextV;}}if(!count){VNode*q;q=(VNode*)malloc(sizeof(VNode));strcpy(q->sc.sno,sno);strcpy(q->sc.sname,sname);strcpy(q->sc.stext,stext);parent->nextV=q;q->nextV=NULL;q->nextArc=NULL;G.vexnum++;cout<<"增加景点信息成功!"<}elsecout<<"增加景点编号重复,请重新增加!"<}//删除景点信息2voidDelete(char*sno1,char*sno2,Graph&G){intcount=0;VNode*address=NULL
if(!
strcmp(sno,p->sc.sno))
returnp;
else
p=p->nextV;
returnNULL;
//系统默认建图
voidDirectCreate(Graph&G)
G.arcnum=16;
G.vexnum=10;
VNode*p1;
VNode*p2;
ArcNode*q1;
ArcNode*q2;
G.V=p1=(VNode*)malloc(sizeof(VNode));
strcpy(p1->sc.sno,"001");
strcpy(p1->sc.sname,"艺术楼");
strcpy(p1->sc.stext,"艺术");
q1=(ArcNode*)malloc(sizeof(ArcNode));
p1->nextArc=q1;
q1->length=60;
strcpy(q1->sno,"009");
q2=(ArcNode*)malloc(sizeof(ArcNode));
q2->length=30;
strcpy(q2->sno,"008");
q2->next=NULL;
q1->next=q2;
p2=(VNode*)malloc(sizeof(VNode));
strcpy(p2->sc.sno,"002");
strcpy(p2->sc.sname,"实验楼");
strcpy(p2->sc.stext,"实验");
p1->nextV=p2;
q1->length=40;
p2->nextArc=q1;
q2->length=150;
strcpy(q2->sno,"006");
p1=(VNode*)malloc(sizeof(VNode));
strcpy(p1->sc.sno,"003");
strcpy(p1->sc.sname,"男生宿舍");
strcpy(p1->sc.stext,"住宿");
p2->nextV=p1;
q1->length=30;
strcpy(q1->sno,"010");
q2->length=75;
strcpy(q2->sno,"005");
strcpy(p2->sc.sno,"004");
strcpy(p2->sc.sname,"女生宿舍");
strcpy(p2->sc.stext,"住宿");
strcpy(q1->sno,"003");
q2->length=100;
strcpy(q2->sno,"007");
strcpy(p1->sc.sno,"005");
strcpy(p1->sc.sname,"小湖");
strcpy(p1->sc.stext,"风景");
q1->length=70;
strcpy(q1->sno,"008");
q2->next=q1;
q2->length=120;
strcpy(q2->sno,"003");
strcpy(p2->sc.sno,"006");
strcpy(p2->sc.sname,"食堂");
strcpy(p2->sc.stext,"吃饭");
strcpy(q2->sno,"002");
q1->length=100;
strcpy(q1->sno,"005");
q1->next=NULL;
strcpy(p1->sc.sno,"007");
strcpy(p1->sc.sname,"图书馆");
strcpy(p1->sc.stext,"借书");
q1->length=120;
strcpy(q2->sno,"004");
strcpy(p2->sc.sno,"008");
strcpy(p2->sc.sname,"篮球场");
strcpy(p2->sc.stext,"运动");
q2->length=70;
strcpy(q1->sno,"001");
q2->length=20;
strcpy(q2->sno,"010");
strcpy(p1->sc.sno,"009");
strcpy(p1->sc.sname,"教学楼");
strcpy(p1->sc.stext,"教学");
strcpy(q1->sno,"002");
q2->length=60;
strcpy(q2->sno,"001");
strcpy(p2->sc.sno,"010");
strcpy(p2->sc.sname,"足球场");
q1->length=20;
p2->nextV=NULL;
//创建图
boolCreate(Graph&G)
VNode*last;
cout<<"请输入景点个数以及道路条数"<cin>>G.vexnum>>G.arcnum;if((G.vexnum<=0)||(G.arcnum<=0))returnfalse;G.V=(VNode*)malloc(sizeof(VNode));last=G.V;cout<<"请输入第1个景点的编号、名称、介绍"<cin>>last->sc.sno>>last->sc.sname>>last->sc.stext;last->nextArc=NULL;for(inti=1;i{p=(VNode*)malloc(sizeof(VNode));cout<<"请输入第"<cin>>p->sc.sno>>p->sc.sname>>p->sc.stext;p->nextArc=NULL;last->nextV=p;last=last->nextV;}last->nextV=NULL;charstartSno[4];charendSno[4];intlength;ArcNode*q=NULL;VNode*address=NULL;for(i=0;i{cout<<"请输入第"<cin>>startSno>>endSno>>length;address=GetAddress(startSno,G);q=(ArcNode*)malloc(sizeof(ArcNode));strcpy(q->sno,endSno);q->length=length;q->next=address->nextArc;address->nextArc=q;/*----------------无向网需正反两次-------------------*/address=GetAddress(endSno,G);q=(ArcNode*)malloc(sizeof(ArcNode));strcpy(q->sno,startSno);q->length=length;q->next=address->nextArc;address->nextArc=q;}returntrue;}//查询相关景点信息voidSearchScenery(Graph&G){intcount=0;VNode*p=G.V;charnoOrName[21];cout<<"请输入你想要查询的景点的编号或名称"<cin>>noOrName;for(inti=0;i{if(!(strcmp(noOrName,p->sc.sno)&&strcmp(noOrName,p->sc.sname))){cout<<"景点编号:"<sc.sno<cout<<"景点名称:"<sc.sname<cout<<"景点介绍:"<sc.stext<count++;break;}elsep=p->nextV;}if(!count)cout<<"查找失败!"<}//增加景点信息voidAddScenery(Graph&G){intcount=0;intflag=0;charsno[4];charsname[21];charstext[201];VNode*g=NULL;cout<<"请输入景点的编号:";cin>>sno;g=G.V;while(g){if(!strcmp(g->sc.sno,sno)){flag++;break;}elseg=g->nextV;}if(flag){cout<<"输入的景点编号重复,请重新插入!"<return;}cout<<"请输入景点的名称:";cin>>sname;cout<<"请输入景点的介绍:";cin>>stext;cout<VNode*p=G.V;VNode*parent=NULL;while(p){if(!strcmp(p->sc.sno,sno)){count++;break;}else{parent=p;p=p->nextV;}}if(!count){VNode*q;q=(VNode*)malloc(sizeof(VNode));strcpy(q->sc.sno,sno);strcpy(q->sc.sname,sname);strcpy(q->sc.stext,stext);parent->nextV=q;q->nextV=NULL;q->nextArc=NULL;G.vexnum++;cout<<"增加景点信息成功!"<}elsecout<<"增加景点编号重复,请重新增加!"<}//删除景点信息2voidDelete(char*sno1,char*sno2,Graph&G){intcount=0;VNode*address=NULL
cin>>G.vexnum>>G.arcnum;
if((G.vexnum<=0)||(G.arcnum<=0))
returnfalse;
G.V=(VNode*)malloc(sizeof(VNode));
last=G.V;
cout<<"请输入第1个景点的编号、名称、介绍"<cin>>last->sc.sno>>last->sc.sname>>last->sc.stext;last->nextArc=NULL;for(inti=1;i{p=(VNode*)malloc(sizeof(VNode));cout<<"请输入第"<cin>>p->sc.sno>>p->sc.sname>>p->sc.stext;p->nextArc=NULL;last->nextV=p;last=last->nextV;}last->nextV=NULL;charstartSno[4];charendSno[4];intlength;ArcNode*q=NULL;VNode*address=NULL;for(i=0;i{cout<<"请输入第"<cin>>startSno>>endSno>>length;address=GetAddress(startSno,G);q=(ArcNode*)malloc(sizeof(ArcNode));strcpy(q->sno,endSno);q->length=length;q->next=address->nextArc;address->nextArc=q;/*----------------无向网需正反两次-------------------*/address=GetAddress(endSno,G);q=(ArcNode*)malloc(sizeof(ArcNode));strcpy(q->sno,startSno);q->length=length;q->next=address->nextArc;address->nextArc=q;}returntrue;}//查询相关景点信息voidSearchScenery(Graph&G){intcount=0;VNode*p=G.V;charnoOrName[21];cout<<"请输入你想要查询的景点的编号或名称"<cin>>noOrName;for(inti=0;i{if(!(strcmp(noOrName,p->sc.sno)&&strcmp(noOrName,p->sc.sname))){cout<<"景点编号:"<sc.sno<cout<<"景点名称:"<sc.sname<cout<<"景点介绍:"<sc.stext<count++;break;}elsep=p->nextV;}if(!count)cout<<"查找失败!"<}//增加景点信息voidAddScenery(Graph&G){intcount=0;intflag=0;charsno[4];charsname[21];charstext[201];VNode*g=NULL;cout<<"请输入景点的编号:";cin>>sno;g=G.V;while(g){if(!strcmp(g->sc.sno,sno)){flag++;break;}elseg=g->nextV;}if(flag){cout<<"输入的景点编号重复,请重新插入!"<return;}cout<<"请输入景点的名称:";cin>>sname;cout<<"请输入景点的介绍:";cin>>stext;cout<VNode*p=G.V;VNode*parent=NULL;while(p){if(!strcmp(p->sc.sno,sno)){count++;break;}else{parent=p;p=p->nextV;}}if(!count){VNode*q;q=(VNode*)malloc(sizeof(VNode));strcpy(q->sc.sno,sno);strcpy(q->sc.sname,sname);strcpy(q->sc.stext,stext);parent->nextV=q;q->nextV=NULL;q->nextArc=NULL;G.vexnum++;cout<<"增加景点信息成功!"<}elsecout<<"增加景点编号重复,请重新增加!"<}//删除景点信息2voidDelete(char*sno1,char*sno2,Graph&G){intcount=0;VNode*address=NULL
cin>>last->sc.sno>>last->sc.sname>>last->sc.stext;
last->nextArc=NULL;
for(inti=1;i{p=(VNode*)malloc(sizeof(VNode));cout<<"请输入第"<cin>>p->sc.sno>>p->sc.sname>>p->sc.stext;p->nextArc=NULL;last->nextV=p;last=last->nextV;}last->nextV=NULL;charstartSno[4];charendSno[4];intlength;ArcNode*q=NULL;VNode*address=NULL;for(i=0;i{cout<<"请输入第"<cin>>startSno>>endSno>>length;address=GetAddress(startSno,G);q=(ArcNode*)malloc(sizeof(ArcNode));strcpy(q->sno,endSno);q->length=length;q->next=address->nextArc;address->nextArc=q;/*----------------无向网需正反两次-------------------*/address=GetAddress(endSno,G);q=(ArcNode*)malloc(sizeof(ArcNode));strcpy(q->sno,startSno);q->length=length;q->next=address->nextArc;address->nextArc=q;}returntrue;}//查询相关景点信息voidSearchScenery(Graph&G){intcount=0;VNode*p=G.V;charnoOrName[21];cout<<"请输入你想要查询的景点的编号或名称"<cin>>noOrName;for(inti=0;i{if(!(strcmp(noOrName,p->sc.sno)&&strcmp(noOrName,p->sc.sname))){cout<<"景点编号:"<sc.sno<cout<<"景点名称:"<sc.sname<cout<<"景点介绍:"<sc.stext<count++;break;}elsep=p->nextV;}if(!count)cout<<"查找失败!"<}//增加景点信息voidAddScenery(Graph&G){intcount=0;intflag=0;charsno[4];charsname[21];charstext[201];VNode*g=NULL;cout<<"请输入景点的编号:";cin>>sno;g=G.V;while(g){if(!strcmp(g->sc.sno,sno)){flag++;break;}elseg=g->nextV;}if(flag){cout<<"输入的景点编号重复,请重新插入!"<return;}cout<<"请输入景点的名称:";cin>>sname;cout<<"请输入景点的介绍:";cin>>stext;cout<VNode*p=G.V;VNode*parent=NULL;while(p){if(!strcmp(p->sc.sno,sno)){count++;break;}else{parent=p;p=p->nextV;}}if(!count){VNode*q;q=(VNode*)malloc(sizeof(VNode));strcpy(q->sc.sno,sno);strcpy(q->sc.sname,sname);strcpy(q->sc.stext,stext);parent->nextV=q;q->nextV=NULL;q->nextArc=NULL;G.vexnum++;cout<<"增加景点信息成功!"<}elsecout<<"增加景点编号重复,请重新增加!"<}//删除景点信息2voidDelete(char*sno1,char*sno2,Graph&G){intcount=0;VNode*address=NULL
p=(VNode*)malloc(sizeof(VNode));
cout<<"请输入第"<
cin>>p->sc.sno>>p->sc.sname>>p->sc.stext;
p->nextArc=NULL;
last->nextV=p;
last=last->nextV;
last->nextV=NULL;
charstartSno[4];
charendSno[4];
intlength;
ArcNode*q=NULL;
VNode*address=NULL;
for(i=0;i{cout<<"请输入第"<cin>>startSno>>endSno>>length;address=GetAddress(startSno,G);q=(ArcNode*)malloc(sizeof(ArcNode));strcpy(q->sno,endSno);q->length=length;q->next=address->nextArc;address->nextArc=q;/*----------------无向网需正反两次-------------------*/address=GetAddress(endSno,G);q=(ArcNode*)malloc(sizeof(ArcNode));strcpy(q->sno,startSno);q->length=length;q->next=address->nextArc;address->nextArc=q;}returntrue;}//查询相关景点信息voidSearchScenery(Graph&G){intcount=0;VNode*p=G.V;charnoOrName[21];cout<<"请输入你想要查询的景点的编号或名称"<cin>>noOrName;for(inti=0;i{if(!(strcmp(noOrName,p->sc.sno)&&strcmp(noOrName,p->sc.sname))){cout<<"景点编号:"<sc.sno<cout<<"景点名称:"<sc.sname<cout<<"景点介绍:"<sc.stext<count++;break;}elsep=p->nextV;}if(!count)cout<<"查找失败!"<}//增加景点信息voidAddScenery(Graph&G){intcount=0;intflag=0;charsno[4];charsname[21];charstext[201];VNode*g=NULL;cout<<"请输入景点的编号:";cin>>sno;g=G.V;while(g){if(!strcmp(g->sc.sno,sno)){flag++;break;}elseg=g->nextV;}if(flag){cout<<"输入的景点编号重复,请重新插入!"<return;}cout<<"请输入景点的名称:";cin>>sname;cout<<"请输入景点的介绍:";cin>>stext;cout<VNode*p=G.V;VNode*parent=NULL;while(p){if(!strcmp(p->sc.sno,sno)){count++;break;}else{parent=p;p=p->nextV;}}if(!count){VNode*q;q=(VNode*)malloc(sizeof(VNode));strcpy(q->sc.sno,sno);strcpy(q->sc.sname,sname);strcpy(q->sc.stext,stext);parent->nextV=q;q->nextV=NULL;q->nextArc=NULL;G.vexnum++;cout<<"增加景点信息成功!"<}elsecout<<"增加景点编号重复,请重新增加!"<}//删除景点信息2voidDelete(char*sno1,char*sno2,Graph&G){intcount=0;VNode*address=NULL
cin>>startSno>>endSno>>length;
address=GetAddress(startSno,G);
q=(ArcNode*)malloc(sizeof(ArcNode));
strcpy(q->sno,endSno);
q->length=length;
q->next=address->nextArc;
address->nextArc=q;
/*----------------无向网需正反两次-------------------*/
address=GetAddress(endSno,G);
strcpy(q->sno,startSno);
returntrue;
//查询相关景点信息
voidSearchScenery(Graph&G)
intcount=0;
VNode*p=G.V;
charnoOrName[21];
cout<<"请输入你想要查询的景点的编号或名称"<cin>>noOrName;for(inti=0;i{if(!(strcmp(noOrName,p->sc.sno)&&strcmp(noOrName,p->sc.sname))){cout<<"景点编号:"<sc.sno<cout<<"景点名称:"<sc.sname<cout<<"景点介绍:"<sc.stext<count++;break;}elsep=p->nextV;}if(!count)cout<<"查找失败!"<}//增加景点信息voidAddScenery(Graph&G){intcount=0;intflag=0;charsno[4];charsname[21];charstext[201];VNode*g=NULL;cout<<"请输入景点的编号:";cin>>sno;g=G.V;while(g){if(!strcmp(g->sc.sno,sno)){flag++;break;}elseg=g->nextV;}if(flag){cout<<"输入的景点编号重复,请重新插入!"<return;}cout<<"请输入景点的名称:";cin>>sname;cout<<"请输入景点的介绍:";cin>>stext;cout<VNode*p=G.V;VNode*parent=NULL;while(p){if(!strcmp(p->sc.sno,sno)){count++;break;}else{parent=p;p=p->nextV;}}if(!count){VNode*q;q=(VNode*)malloc(sizeof(VNode));strcpy(q->sc.sno,sno);strcpy(q->sc.sname,sname);strcpy(q->sc.stext,stext);parent->nextV=q;q->nextV=NULL;q->nextArc=NULL;G.vexnum++;cout<<"增加景点信息成功!"<}elsecout<<"增加景点编号重复,请重新增加!"<}//删除景点信息2voidDelete(char*sno1,char*sno2,Graph&G){intcount=0;VNode*address=NULL
cin>>noOrName;
for(inti=0;i{if(!(strcmp(noOrName,p->sc.sno)&&strcmp(noOrName,p->sc.sname))){cout<<"景点编号:"<sc.sno<cout<<"景点名称:"<sc.sname<cout<<"景点介绍:"<sc.stext<count++;break;}elsep=p->nextV;}if(!count)cout<<"查找失败!"<}//增加景点信息voidAddScenery(Graph&G){intcount=0;intflag=0;charsno[4];charsname[21];charstext[201];VNode*g=NULL;cout<<"请输入景点的编号:";cin>>sno;g=G.V;while(g){if(!strcmp(g->sc.sno,sno)){flag++;break;}elseg=g->nextV;}if(flag){cout<<"输入的景点编号重复,请重新插入!"<return;}cout<<"请输入景点的名称:";cin>>sname;cout<<"请输入景点的介绍:";cin>>stext;cout<VNode*p=G.V;VNode*parent=NULL;while(p){if(!strcmp(p->sc.sno,sno)){count++;break;}else{parent=p;p=p->nextV;}}if(!count){VNode*q;q=(VNode*)malloc(sizeof(VNode));strcpy(q->sc.sno,sno);strcpy(q->sc.sname,sname);strcpy(q->sc.stext,stext);parent->nextV=q;q->nextV=NULL;q->nextArc=NULL;G.vexnum++;cout<<"增加景点信息成功!"<}elsecout<<"增加景点编号重复,请重新增加!"<}//删除景点信息2voidDelete(char*sno1,char*sno2,Graph&G){intcount=0;VNode*address=NULL
(strcmp(noOrName,p->sc.sno)&&strcmp(noOrName,p->sc.sname)))
cout<<"景点编号:
"<sc.sno<cout<<"景点名称:"<sc.sname<cout<<"景点介绍:"<sc.stext<count++;break;}elsep=p->nextV;}if(!count)cout<<"查找失败!"<}//增加景点信息voidAddScenery(Graph&G){intcount=0;intflag=0;charsno[4];charsname[21];charstext[201];VNode*g=NULL;cout<<"请输入景点的编号:";cin>>sno;g=G.V;while(g){if(!strcmp(g->sc.sno,sno)){flag++;break;}elseg=g->nextV;}if(flag){cout<<"输入的景点编号重复,请重新插入!"<return;}cout<<"请输入景点的名称:";cin>>sname;cout<<"请输入景点的介绍:";cin>>stext;cout<VNode*p=G.V;VNode*parent=NULL;while(p){if(!strcmp(p->sc.sno,sno)){count++;break;}else{parent=p;p=p->nextV;}}if(!count){VNode*q;q=(VNode*)malloc(sizeof(VNode));strcpy(q->sc.sno,sno);strcpy(q->sc.sname,sname);strcpy(q->sc.stext,stext);parent->nextV=q;q->nextV=NULL;q->nextArc=NULL;G.vexnum++;cout<<"增加景点信息成功!"<}elsecout<<"增加景点编号重复,请重新增加!"<}//删除景点信息2voidDelete(char*sno1,char*sno2,Graph&G){intcount=0;VNode*address=NULL
cout<<"景点名称:
"<sc.sname<cout<<"景点介绍:"<sc.stext<count++;break;}elsep=p->nextV;}if(!count)cout<<"查找失败!"<}//增加景点信息voidAddScenery(Graph&G){intcount=0;intflag=0;charsno[4];charsname[21];charstext[201];VNode*g=NULL;cout<<"请输入景点的编号:";cin>>sno;g=G.V;while(g){if(!strcmp(g->sc.sno,sno)){flag++;break;}elseg=g->nextV;}if(flag){cout<<"输入的景点编号重复,请重新插入!"<return;}cout<<"请输入景点的名称:";cin>>sname;cout<<"请输入景点的介绍:";cin>>stext;cout<VNode*p=G.V;VNode*parent=NULL;while(p){if(!strcmp(p->sc.sno,sno)){count++;break;}else{parent=p;p=p->nextV;}}if(!count){VNode*q;q=(VNode*)malloc(sizeof(VNode));strcpy(q->sc.sno,sno);strcpy(q->sc.sname,sname);strcpy(q->sc.stext,stext);parent->nextV=q;q->nextV=NULL;q->nextArc=NULL;G.vexnum++;cout<<"增加景点信息成功!"<}elsecout<<"增加景点编号重复,请重新增加!"<}//删除景点信息2voidDelete(char*sno1,char*sno2,Graph&G){intcount=0;VNode*address=NULL
cout<<"景点介绍:
"<sc.stext<count++;break;}elsep=p->nextV;}if(!count)cout<<"查找失败!"<}//增加景点信息voidAddScenery(Graph&G){intcount=0;intflag=0;charsno[4];charsname[21];charstext[201];VNode*g=NULL;cout<<"请输入景点的编号:";cin>>sno;g=G.V;while(g){if(!strcmp(g->sc.sno,sno)){flag++;break;}elseg=g->nextV;}if(flag){cout<<"输入的景点编号重复,请重新插入!"<return;}cout<<"请输入景点的名称:";cin>>sname;cout<<"请输入景点的介绍:";cin>>stext;cout<VNode*p=G.V;VNode*parent=NULL;while(p){if(!strcmp(p->sc.sno,sno)){count++;break;}else{parent=p;p=p->nextV;}}if(!count){VNode*q;q=(VNode*)malloc(sizeof(VNode));strcpy(q->sc.sno,sno);strcpy(q->sc.sname,sname);strcpy(q->sc.stext,stext);parent->nextV=q;q->nextV=NULL;q->nextArc=NULL;G.vexnum++;cout<<"增加景点信息成功!"<}elsecout<<"增加景点编号重复,请重新增加!"<}//删除景点信息2voidDelete(char*sno1,char*sno2,Graph&G){intcount=0;VNode*address=NULL
count++;
break;
count)
cout<<"查找失败!
"<}//增加景点信息voidAddScenery(Graph&G){intcount=0;intflag=0;charsno[4];charsname[21];charstext[201];VNode*g=NULL;cout<<"请输入景点的编号:";cin>>sno;g=G.V;while(g){if(!strcmp(g->sc.sno,sno)){flag++;break;}elseg=g->nextV;}if(flag){cout<<"输入的景点编号重复,请重新插入!"<return;}cout<<"请输入景点的名称:";cin>>sname;cout<<"请输入景点的介绍:";cin>>stext;cout<VNode*p=G.V;VNode*parent=NULL;while(p){if(!strcmp(p->sc.sno,sno)){count++;break;}else{parent=p;p=p->nextV;}}if(!count){VNode*q;q=(VNode*)malloc(sizeof(VNode));strcpy(q->sc.sno,sno);strcpy(q->sc.sname,sname);strcpy(q->sc.stext,stext);parent->nextV=q;q->nextV=NULL;q->nextArc=NULL;G.vexnum++;cout<<"增加景点信息成功!"<}elsecout<<"增加景点编号重复,请重新增加!"<}//删除景点信息2voidDelete(char*sno1,char*sno2,Graph&G){intcount=0;VNode*address=NULL
//增加景点信息
voidAddScenery(Graph&G)
intflag=0;
charsno[4];
charsname[21];
charstext[201];
VNode*g=NULL;
cout<<"请输入景点的编号:
";
cin>>sno;
g=G.V;
while(g)
strcmp(g->sc.sno,sno))
flag++;
g=g->nextV;
if(flag)
cout<<"输入的景点编号重复,请重新插入!
"<return;}cout<<"请输入景点的名称:";cin>>sname;cout<<"请输入景点的介绍:";cin>>stext;cout<VNode*p=G.V;VNode*parent=NULL;while(p){if(!strcmp(p->sc.sno,sno)){count++;break;}else{parent=p;p=p->nextV;}}if(!count){VNode*q;q=(VNode*)malloc(sizeof(VNode));strcpy(q->sc.sno,sno);strcpy(q->sc.sname,sname);strcpy(q->sc.stext,stext);parent->nextV=q;q->nextV=NULL;q->nextArc=NULL;G.vexnum++;cout<<"增加景点信息成功!"<}elsecout<<"增加景点编号重复,请重新增加!"<}//删除景点信息2voidDelete(char*sno1,char*sno2,Graph&G){intcount=0;VNode*address=NULL
return;
cout<<"请输入景点的名称:
cin>>sname;
cout<<"请输入景点的介绍:
cin>>stext;
cout<VNode*p=G.V;VNode*parent=NULL;while(p){if(!strcmp(p->sc.sno,sno)){count++;break;}else{parent=p;p=p->nextV;}}if(!count){VNode*q;q=(VNode*)malloc(sizeof(VNode));strcpy(q->sc.sno,sno);strcpy(q->sc.sname,sname);strcpy(q->sc.stext,stext);parent->nextV=q;q->nextV=NULL;q->nextArc=NULL;G.vexnum++;cout<<"增加景点信息成功!"<}elsecout<<"增加景点编号重复,请重新增加!"<}//删除景点信息2voidDelete(char*sno1,char*sno2,Graph&G){intcount=0;VNode*address=NULL
VNode*parent=NULL;
while(p)
strcmp(p->sc.sno,sno))
parent=p;
VNode*q;
q=(VNode*)malloc(sizeof(VNode));
strcpy(q->sc.sno,sno);
strcpy(q->sc.sname,sname);
strcpy(q->sc.stext,stext);
parent->nextV=q;
q->nextV=NULL;
q->nextArc=NULL;
G.vexnum++;
cout<<"增加景点信息成功!
"<}elsecout<<"增加景点编号重复,请重新增加!"<}//删除景点信息2voidDelete(char*sno1,char*sno2,Graph&G){intcount=0;VNode*address=NULL
cout<<"增加景点编号重复,请重新增加!
"<}//删除景点信息2voidDelete(char*sno1,char*sno2,Graph&G){intcount=0;VNode*address=NULL
//删除景点信息2
voidDelete(char*sno1,char*sno2,Graph&G)
VNode*address=NULL
copyright@ 2008-2022 冰豆网网站版权所有
经营许可证编号:鄂ICP备2022015515号-1