数据结构校园导航.docx
《数据结构校园导航.docx》由会员分享,可在线阅读,更多相关《数据结构校园导航.docx(19页珍藏版)》请在冰点文库上搜索。
![数据结构校园导航.docx](https://file1.bingdoc.com/fileroot1/2023-6/20/daac102a-0fac-4667-87b1-7706eb509806/daac102a-0fac-4667-87b1-7706eb5098061.gif)
数据结构校园导航
//campus.cpp:
Definestheentrypointfortheconsoleapplication.
//
#include
#include
#include
//////////////////////////////
classEdge//定义边
{
public:
intard;//下标
Edge*list;
intworth;//权重
};
////////////////////////////////
classGraph//定义顶点
{
public:
charname[10],other[40];
intup,down;
Edge*list;//存放边路
};
////////////////////////////////
classMenu
{
public:
voidMenu_star();
voidMenu_Second();
voidnavigation();
voidMenu_main();
voidAdd();
voidSearch();
voidUpdate();
private:
intMaxVertices;//顶点数
char**map;//地图
intNumEdges;//边数
intmax_map;//虚拟地图大小
intfound_adress(charstd[10]);
bool*flag;
voidGraph_map();
Graph*Vertices;
voidPrint();//输出
bool*help;//辅助布尔数组
};
//////////////////////菜单
voidMenu:
:
Menu_Second()
{
flag=newbool[MaxVertices];
inti=0;
for(i=0;iflag[i]=false;
intselect;
while(select!
=6)
{
cout<<"主菜单"<cout<<"_______________________________________________________________________________"<cout<<"*******************************************************************************"<cout<cout<cout<cout<cout<<"1-输出地图"<cout<<"2-地图导航"<cout<<"3-建筑查询"<cout<<"4-建筑详情添加"<cout<<"5-更新"<cout<<"6-退出"<cout<<"";
cin>>select;
switch(select)
{
case1:
Print();break;
case2:
navigation();break;
case3:
Search();break;
case4:
Add();break;
case5:
Update();break;
}
}
}
voidMenu:
:
Menu_main()
{
cout<cout<cout<cout<cout<cout<cout<cout<cout<<"STARGAME"<cout<<"<请输任意键开始>"<getchar();
Menu_star();
Menu_Second();
}
////////////////////////////////
voidMenu:
:
Update()
{
inti,j;
cout<<"请输入增加建筑数目";
cin>>i;
Graph*p;
p=newGraph[MaxVertices+i];
for(j=0;j{
p[j]=Vertices[j];
}
deleteVertices;
for(j=MaxVertices;j{
cout<<"第"<cout<<"请输入建筑坐标";
cin>>p[j].up>>p[j].down;
p[j].up=p[j].up*2;
p[j].down=p[i].down*2;
cout<<"请输入建筑名称";
cin>>p[j].name;
p[j].list=NULL;
}
Vertices=p;
MaxVertices=j;
Edge*s1,*s2;
intworth,k,f;
charv1[10],v2[10];
cout<<"输入新建筑与其他建筑边数"<cin>>i;
for(f=0;f
{
cout<<"请输入"<cin>>v1>>v2;
cout<<"请输入该边权重";
cin>>worth;
k=found_adress(v1);
j=found_adress(v2);
s1=newEdge;
s1->worth=worth;
s1->ard=j;
s1->list=Vertices[k].list;
Vertices[k].list=s1;
s2=newEdge;
s2->worth=worth;
s2->ard=k;
s2->list=Vertices[j].list;
Vertices[j].list=s2;
}
NumEdges=NumEdges+i;
cout<for(i=0;ifor(j=0;jmap[i][j]='';
for(i=0;imap[Vertices[i].up][Vertices[i].down]='A'+i;
Graph_map();
}
voidMenu:
:
Search()
{
cout<<"建筑信息搜索"<cout<<"_______________________________________________________________________________"<cout<<"*******************************************************************************"<charstd[20];
inti,j,k;
cout<<"请输入您想要检索的内容";
cin>>std;
for(i=0;i{
k=0;
for(j=0;j{
if(Vertices[i].name[j]==std[j])
k++;
if(k>strlen(Vertices[i].name)/2)
cout<<"简单搜索的结果"<}
k=0;
if(k{
for(j=0;j{
if(Vertices[i].name[j]==std[j])
k++;
if(k>strlen(Vertices[i].name))
cout<<"简单搜索的结果"<}
if(k>strlen(Vertices[i].name)/2)
cout<<"简单搜索的结果"<}
}
}
voidMenu:
:
navigation()
{
cout<<"地图导航"<cout<<"_______________________________________________________________________________"<cout<<"*******************************************************************************"<Edge*p;
intmove=0;
int*nave;
inti,ad,j,test,end;
charouradree[10];
cout<<"亲,请先确定当前地点"<int*adree_name;
cin>>ouradree;
ad=found_adress(ouradree);
cout<<"请输入终点";
cin>>ouradree;
end=found_adress(ouradree);
adree_name=newint[MaxVertices];
nave=newint[MaxVertices];
help=newbool[MaxVertices];
for(i=0;i{nave[i]=1000;help[i]=true;}
nave[ad]=0;
for(i=0;i{
if(ad==end)break;
p=Vertices[ad].list;
help[ad]=false;
adree_name[move++]=ad;
while(p!
=NULL)
{
if(nave[p->ard]>p->worth&&help[p->ard])nave[p->ard]=p->worth+nave[ad];
p=p->list;
}
test=1000;
for(j=0;j{
if(help[j])
{
if(nave[j]}
}
}
cout<<"开始导航"<for(i=0;i{
cout<<""<
}
cout<<"总计路程:
"<}
////////////////////////
voidMenu:
:
Add()
{
charstd[10];
charadjuct;
inti;
cout<<"添加建筑信息"<cout<<"_______________________________________________________________________________"<cout<<"*******************************************************************************"<while(true)
{
cout<<"请输入建筑名称"<cin>>std;
i=found_adress(std);
cout<<"您所要添加的建筑信息为"<cout<<"友情提示!
您可以为建筑添加更多的信息更方便搜索"<cout<<"请输入:
";
cin>>Vertices[i].other;
flag[i]=true;
cout<<"是否继续添加?
(Y/N)";
cin>>adjuct;
if(adjuct=='N'||adjuct=='n')break;
}
cout<<"OK,添加成功"<}
////////////////////////
voidMenu:
:
Graph_map()//画出虚拟图
{
help=newbool[MaxVertices];
Edge*p;
inti,v1,v2,vf1,vf2;
for(i=0;ihelp[i]=false;
for(i=0;i{
p=Vertices[i].list;
while(p!
=NULL)
{v1=Vertices[i].up;
v2=Vertices[i].down;
if(help[p->ard]==false)
while(!
(v1==Vertices[p->ard].up&&v2==Vertices[p->ard].down))
{
if(v1==Vertices[p->ard].up)
{vf1=0;
if(v2ard].down)
vf2=1;
else
vf2=-1;
}
elseif(v2==Vertices[p->ard].down)
{
vf2=0;
if(v1ard].up)
vf1=1;
else
vf1=-1;
}
elseif(v1ard].up)
{vf1=1;
if(v2ard].down)
vf2=1;
else
vf2=-1;
}
elseif(v1>Vertices[p->ard].up)
{
vf1=-1;
if(v2ard].down)
vf2=1;
else
vf2=-1;
}
if(map[v1+vf1][v2+vf2]>='A'&&map[v1+vf1][v2+vf2]<='Z')break;
while(true)
{
if(map[v1+vf1][v2+vf2]!
='*')
{
map[v1+vf1][v2+vf2]='*';
v1=v1+vf1;v2=v2+vf2;break;
}
else
if(map[v1+vf1][v2+vf2*(-1)]!
='*')
vf2=vf2*(-1);
elseif(map[v1+vf1*(-1)][v2+vf2]!
='*')
vf1=vf1*(-1);
else
if(map[v1+vf1*(-1)][v2+vf2*(-1)]!
='*')
{vf1=vf1*(-1);vf2=vf2*(-1);}
}
}
p=p->list;
}
help[i]=true;
}
delete[]help;
}
////////////////////////////////////
voidMenu:
:
Print()//输出
{
cout<<"地图输出"<cout<<"_______________________________________________________________________________"<cout<<"*******************************************************************************"<inti,j;
for(i=0;i{cout<<"";
for(j=0;jcout<