数据结构校园导航.docx

上传人:b****1 文档编号:14069444 上传时间:2023-06-20 格式:DOCX 页数:19 大小:17.46KB
下载 相关 举报
数据结构校园导航.docx_第1页
第1页 / 共19页
数据结构校园导航.docx_第2页
第2页 / 共19页
数据结构校园导航.docx_第3页
第3页 / 共19页
数据结构校园导航.docx_第4页
第4页 / 共19页
数据结构校园导航.docx_第5页
第5页 / 共19页
数据结构校园导航.docx_第6页
第6页 / 共19页
数据结构校园导航.docx_第7页
第7页 / 共19页
数据结构校园导航.docx_第8页
第8页 / 共19页
数据结构校园导航.docx_第9页
第9页 / 共19页
数据结构校园导航.docx_第10页
第10页 / 共19页
数据结构校园导航.docx_第11页
第11页 / 共19页
数据结构校园导航.docx_第12页
第12页 / 共19页
数据结构校园导航.docx_第13页
第13页 / 共19页
数据结构校园导航.docx_第14页
第14页 / 共19页
数据结构校园导航.docx_第15页
第15页 / 共19页
数据结构校园导航.docx_第16页
第16页 / 共19页
数据结构校园导航.docx_第17页
第17页 / 共19页
数据结构校园导航.docx_第18页
第18页 / 共19页
数据结构校园导航.docx_第19页
第19页 / 共19页
亲,该文档总共19页,全部预览完了,如果喜欢就下载吧!
下载资源
资源描述

数据结构校园导航.docx

《数据结构校园导航.docx》由会员分享,可在线阅读,更多相关《数据结构校园导航.docx(19页珍藏版)》请在冰点文库上搜索。

数据结构校园导航.docx

数据结构校园导航

//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;i

flag[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;i

for(j=0;j

map[i][j]='';

for(i=0;i

map[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;i

help[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;j

cout<

cout<

}

cout<<"_______________________________________________________________________________"<

cout<<"建筑信息"<

for(i=0;i

{

cout<<(char)('A'+i)<<"--"<

}

cout<

for(i=0;i

if(!

flag[i])

cout<<"尚未赋值"<<"";

else

cout<

cout<

}

//////////////////////////////

voidMenu:

:

Menu_star()

{cout<<"欢迎使用"<

cout<<"_______________________________________________________________________________"<

cout<<"*******************************************************************************"<

cout<<"亲,请先构建地图"<

cout<<"请输入地图大小";

cin>>max_map;

inti,j,k;

cout<<"";

for(i=0;i

{

cout<

if(i+1>=10)cout<<"";

elsecout<<"";

}

cout<

for(i=0;i

{

cout<<""<

if(i+1>=10)cout<<"";

elsecout<<"";

for(j=0;j

cout<<'-';

cout<

cout<<"";

if(i==max_map-1)continue;

for(j=0;j

cout<<"|";

cout<

}

////

///输入建筑坐标

cout<<"请输入建筑数";

cin>>MaxVertices;

Vertices=newGraph[MaxVertices];

for(i=0;i

{

cout<<"第"<

cout<<"请输入建筑坐标";

cin>>Vertices[i].up>>Vertices[i].down;

Vertices[i].up=Vertices[i].up*2;

Vertices[i].down=Vertices[i].down*2;

cout<<"请输入建筑名称";

cin>>Vertices[i].name;

Vertices[i].list=NULL;

}

Edge*s1,*s2;

intworth;

charstd;

charv1[10],v2[10];

cout<<"输入边数"<

cin>>NumEdges;

for(i=0;i

{

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;

}

map=newchar*[max_map*2];

for(i=0;i

map[i]=newchar[max_map*2];

for(i=0;i

for(j=0;j

map[i][j]='';

for(i=0;i

map[Vertices[i].up][Vertices[i].down]='A'+i;

Graph_map();

}

intMenu:

:

found_adress(charstd[])

{

inti=0;

for(;i

if(strcmp(Vertices[i].name,std)==0)

returni;

}

voidmain()

{

Menustar;

star.Menu_main();

}

展开阅读全文
相关资源
猜你喜欢
相关搜索
资源标签

当前位置:首页 > 农林牧渔 > 林学

copyright@ 2008-2023 冰点文库 网站版权所有

经营许可证编号:鄂ICP备19020893号-2