校园导航系统数据结构课程设计报告书(编辑修改稿)内容摘要:

9| \n)。 printf( (7)library(8)No. 1 teaching building(9)No. 13 teaching building\n)。 printf(\n\n\n)。 } 4)输出地点信息的 information 函数 void Information() { int number。 while(1) { printf(Please enter the number of query site:)。 scanf(%d,amp。 number)。 if(number MAX_VERTEX_NUM amp。 amp。 number 0) { printf(\n@name: %s\n@introduction:%s\n,vertex[number].name,vertex[number].introduce)。 return。 } else { printf(input error!!\n)。 } } } 5)最短路径 floyd 函数 void floyd()/*弗洛伊德算法 */ { int i, j, u。 10 for(i = 1。 i MAX_VERTEX_NUM。 ++i) { for(j = 1。 j MAX_VERTEX_NUM。 ++j) { shortest[i][j] = dist[i][j]。 path[i][j] = 0。 } } for(u = 1。 u MAX_VERTEX_NUM。 ++u) { for(i = 1。 i MAX_VERTEX_NUM。 ++i) { for(j = 1。 j MAX_VERTEX_NUM。 ++j) { if(shortest[i][j] (shortest[i][u] + shortest[u][j])) { shortest[i][j] = shortest[i][u] + shortest[u][j]。 path[i][j] = path[j][i] = u。 } } } } } 6)输出路径 Path 算法 void Path(int i, int j)/*最短路径的输出 */ { int u = 0。 int a,b。 a = i。 11 b = j。 if(shortest[i][j] != INFINITY) { printf(\nThe shortest path from %s to %s is:\n\n,vertex[i].name,vertex[j].name)。 printf(%s,vertex[i].name)。 while(path[i][j] != 0) { u = path[i][j]。 while(path[i][u] != 0) { u = path[i][u]。 } printf(%s,vertex[u].name)。 i = u。 } printf(%s。 \n,vertex[j].name)。 printf(\nThe shortest distance is:%d meters.\n,shortest[a][b])。 } } 7)调用 floyd 和 Path 的最短路径 shortestpath 算法 void shortestpath() { int i, j。 while(1) { printf(Please enter the number two to query :)。 scanf(%d%d, amp。 i, amp。 j)。 if(i 0 amp。 amp。 i MAX_VERTEX_NUM amp。 amp。 j 0 amp。 amp。 j MAX_VERTEX_NUM) { 12 floyd()。 //printf(==========\n)。 Path(i,j)。 return。 } } } 3. 函数的调用关系 测试与分析 测试 1) 打开程序后,出现我校平面图和菜单选项,如图所示 main Main Init map s i e Shortsetpath() exit Information() 13 2) 2) 选“ i”,查询对应地点的信息,如输入“ 3”,而后会继续输出菜单,如图所示 3)选“ s”,查询两点之间的信息,如输入“ 1 7”, 而后会继续输出菜单, 如图所示 4)选“ e”,推出 程序,如图所示 分析 14 ;给出图中所要求点的信息。 在调试过程中,除了简单语法错误外,就是对弗洛伊德算法的理解和实现,以及菜单的设置,这是我以前没有实现过的。 出于简单化,并没有对有向图中各个点进行输入,而是在程序中直接赋值。 ,由于有弗洛伊德算法时间复杂度大多数是 O(n3),空间上增加了二维数组,空间复杂度为 O(n+s)。 附录 include include //include define MAX_VERTEX_NUM 10 define INFINITY 10000000 typedef struct { char name[100]。 int number。 char introduce[100]。 }Vertex。 Vertex vertex[MAX_VERTEX_NUM]。 int dist[MAX_VERTEX_NUM][MAX_VERTEX_NUM]。 int shortest[MAX_VERTEX_NUM][MAX_VERTEX_NUM]。 int path[MAX_VERTEX_NUM][MAX_VERTEX_NUM]。 void map() { printf( the science and technology of Shandong university map\n)。 printf(\n\n)。 printf(。
阅读剩余 0%
本站所有文章资讯、展示的图片素材等内容均为注册用户上传(部分报媒/平媒内容转载自网络合作媒体),仅供学习参考。 用户通过本站上传、发布的任何内容的知识产权归属用户或原始著作权人所有。如有侵犯您的版权,请联系我们反馈本站将在三个工作日内改正。