校园导游程序.docx

上传人:b****1 文档编号:856403 上传时间:2022-10-13 格式:DOCX 页数:11 大小:56.02KB
下载 相关 举报
校园导游程序.docx_第1页
第1页 / 共11页
校园导游程序.docx_第2页
第2页 / 共11页
校园导游程序.docx_第3页
第3页 / 共11页
校园导游程序.docx_第4页
第4页 / 共11页
校园导游程序.docx_第5页
第5页 / 共11页
点击查看更多>>
下载资源
资源描述

校园导游程序.docx

《校园导游程序.docx》由会员分享,可在线阅读,更多相关《校园导游程序.docx(11页珍藏版)》请在冰豆网上搜索。

校园导游程序.docx

校园导游程序

 

《数据结构》

课程设计报告

 

姓名:

学号:

班级:

学院:

 

日期:

一、课程设计题目:

校园导游程序

二、需求分析

[问题描述]

用无向网表示你所在学校的校园景点平面图,图中顶点表示主要景点,存放景点的编号、名称、简介等信息,图中的边表示景点间的道路,存放路径长度等信息。

[要求]

(1)查询各景点的相关信息;

(2)查询图中任意两个景点间的最短路径。

(3)查询图中任意两个景点间的所有路径。

(4)增加、删除、更新有关景点和道路的信息。

三、概要设计

主要通过无向图的算法函数来实现校园导游程序设计。

即如下函数:

(本程序可完成创建景点操作,但不能完成分步的增加、删除、更新有关景点和道路的信息的操作。

typedefstructArCell

{

intadj;//路径长度

}ArCell,AdjMatrix[MAX_VERTEX_NUM][MAX_VERTEX_NUM];

typedefstruct//图中顶点表示主要景点,存放景点的编号、名称、简介等信息,

{

charname[30];//景点名

intnum;//编号

charintroduction[100];//简介

}infotype;

typedefstruct

{

infotypevexs[MAX_VERTEX_NUM];

AdjMatrixarcs;//路径

intvexnum,arcnum;//结点数,弧度数

}MGraph;MGraphb;

MGraphInitGraph(void);//无向图初始化

voidBrowser(MGraph*G);//输出图的景点信息,编号,景点名,景点信息。

voidShortestPath_DIJ(MGraph*G);//迪杰斯特拉算法来计算出起点到各个顶点之间的最短路径

voidFloyd(MGraph*G);//计算两景点间的最短路径

intLocateVex(MGraph*G,char*v);//查找景点

MGraph*CreateUDN(MGraph*G);//创建新的图景点

voidprint(MGraph*G);//输出路径长度

 

voidmain(void)//主程序

{

inti;

b=InitGraph();

while(i!

=5)

{printf("\n太原工业导游系统\n");

printf("1.浏览校园全境\n");

printf("2.查看所有游览路径\n");

printf("3.选择出发地点和目的地\n");

printf("4.创建新的景点信息\n");

printf("5.退出\n");

printf("Option-:

");

scanf("%d",&i);

switch(i)

{//调用操作函数

case1:

system("cls");Browser(&b);break;

case2:

system("cls");ShortestPath_DIJ(&b);break;

case3:

system("cls");Floyd(&b);break;

case4:

system("cls");CreateUDN(&b);break;

case5:

exit

(1);break;

default:

break;

}

}

}

四、详细设计

以下为函数的内容:

MGraphInitGraph(void)

{

MGraphG;

inti,j;

G.vexnum=10;

G.arcnum=14;

for(i=0;i

G.vexs[i].num=i;

strcpy(G.vexs[0].name,"体育场");

strcpy(G.vexs[0].introduction,"树胶跑道,足球场等体育用地");

strcpy(G.vexs[1].name,"篮球场");

strcpy(G.vexs[1].introduction,"篮球爱好者的天堂");

strcpy(G.vexs[2].name,"主教学楼");

strcpy(G.vexs[2].introduction,"高层建筑,多媒体教室,适宜学习");

strcpy(G.vexs[3].name,"锅炉房");

strcpy(G.vexs[3].introduction,"长期供热水,冬日供暖");

strcpy(G.vexs[4].name,"东区食堂");

strcpy(G.vexs[4].introduction,"标准食堂建筑");

strcpy(G.vexs[5].name,"实验楼");

strcpy(G.vexs[5].introduction,"实验重地,科研开发");

strcpy(G.vexs[6].name,"办公楼");

strcpy(G.vexs[6].introduction,"教师办公室和学校部门");

strcpy(G.vexs[7].name,"图书馆");

strcpy(G.vexs[7].introduction,"藏书60万册,设施良好,2楼为电子阅览室,环境幽雅");

strcpy(G.vexs[8].name,"沁园");

strcpy(G.vexs[8].introduction,"绿树成荫,适宜休息和读书");

strcpy(G.vexs[9].name,"西区食堂");

strcpy(G.vexs[9].introduction,"标准食堂建筑");

for(i=0;i

for(j=0;j

G.arcs[i][j].adj=INFINITY;

G.arcs[0][1].adj=20;

G.arcs[1][2].adj=200;G.arcs[2][3].adj=80;

G.arcs[2][4].adj=150;G.arcs[3][4].adj=100;

G.arcs[3][5].adj=220;G.arcs[3][6].adj=220;

G.arcs[5][7].adj=140;G.arcs[5][6].adj=100;

G.arcs[5][8].adj=350;G.arcs[6][8].adj=80;

G.arcs[6][7].adj=170;G.arcs[7][9].adj=70;

G.arcs[8][9].adj=70;

for(i=0;i

for(j=0;j

G.arcs[j][i].adj=G.arcs[i][j].adj;

returnG;

}//InitGraphend

voidBrowser(MGraph*G)

{intv;

printf("编号景点名称简介\n");

for(v=0;vvexnum;v++)

printf("%-4d%-16s%-56s\n",G->vexs[v].num,G->vexs[v].name,

G->vexs[v].introduction);

}

voidShortestPath_DIJ(MGraph*G)

{

intv,w,i,min,t=0,x,flag=1,v0;

intfinal[20],D[20],p[20][20];

while(flag)

{

printf("请输入一个起始景点编号:

");

scanf("%d",&v0);

if(v0<0||v0>G->vexnum)

{printf("景点编号不存在!

请重新输入景点编号:

");scanf("%d",&v0);}

if(v0>=0&&v0vexnum)

flag=0;

}

for(v=0;vvexnum;v++)

{final[v]=0;D[v]=G->arcs[v0][v].adj;

for(w=0;wvexnum;w++)

p[v][w]=0;

if(D[v]

{p[v][v0]=1;p[v][v]=1;}

}

D[v0]=0;final[v0]=1;

for(i=1;ivexnum;i++)

{

min=INFINITY;

for(w=0;wvexnum;w++)

if(!

final[w])

if(D[w]

final[v]=1;

for(w=0;wvexnum;w++)

if(!

final[w]&&(min+G->arcs[v][w].adj

{

D[w]=min+G->arcs[v][w].adj;

for(x=0;xvexnum;x++)

p[w][x]=p[v][x];

p[w][w]=1;

}

}

for(v=0;vvexnum;v++)

{

if(v0!

=v)printf("%s",G->vexs[v0].name);

for(w=0;wvexnum;w++)

{

if(p[v][w]&&w!

=v0)printf("-->%s",G->vexs[w].name);

t++;

}

if(t>G->vexnum-1&&v0!

=v)printf("总路线长%dm\n\n",D[v]);

}

}//ShortestPath_DIJend

voidFloyd(MGraph*G)

{intv,u,i,w,k,j,flag=1,p[10][10][10],D[10][10];

for(v=0;vvexnum;v++)

for(w=0;wvexnum;w++)

{

D[v][w]=G->arcs[v][w].adj;

for(u=0;uvexnum;u++)

p[v][w][u]=0;

if(D[v][w]

{

p[v][w][v]=1;p[v][w][w]=1;

}

}

for(u=0;uvexnum;u++)

for(v=0;vvexnum;v++)

for(w=0;wvexnum;w++)

if(D[v][u]+D[u][w]

{

D[v][w]=D[v][u]+D[u][w];

for(i=0;ivexnum;i++)

p[v][w][i]=p[v][u][i]||p[u][w][i];

}

while(flag)

{

printf("请输入出发点和目的地的编号:

");

scanf("%d%d",&k,&j);

if(k<0||k>G->vexnum||j<0||j>G->vexnum)

{

printf("景点编号不存在!

请重新输入出发点和目的地的编号:

");

scanf("%d%d",&k,&j);

}

if(k>=0&&kvexnum&&j>=0&&jvexnum)

flag=0;

}

printf("%s",G->vexs[k].name);

for(u=0;uvexnum;u++)

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

当前位置:首页 > 幼儿教育 > 幼儿读物

copyright@ 2008-2022 冰豆网网站版权所有

经营许可证编号:鄂ICP备2022015515号-1