登录
首页 » 其他项目 » [输入] 图的顶点个数N,图中顶点之间的关系及起点A和终点B [输出] 若A到B无路径,则输出“There is no path” 否则输出A到B路...

[输入] 图的顶点个数N,图中顶点之间的关系及起点A和终点B [输出] 若A到B无路径,则输出“There is no path” 否则输出A到B路...

于 2022-01-25 发布 文件大小:9.72 kB
0 204
下载积分: 2 下载次数: 1

代码说明:

[输入] 图的顶点个数N,图中顶点之间的关系及起点A和终点B [输出] 若A到B无路径,则输出“There is no path” 否则输出A到B路径上个顶点 [存储结构] 图采用邻接矩阵的方式存储。 [算法的基本思想] 采用广度优先搜索的方法,从顶点A开始,依次访问与A邻接的顶点VA1,VA2,...,VAK, 访问遍之后,若没有访问B,则继续访问与VA1邻接的顶点VA11,VA12,...,VA1M,再访问与VA2邻接顶点...,如此下去,直至找到B,最先到达B点的路径,一定是边数最少的路径。实现时采用队列记录被访问过的顶点。每次访问与队头顶点相邻接的顶点,然后将队头顶点从队列中删去。若队空,则说明到不存在通路。在访问顶点过程中,每次把当前顶点的序号作为与其邻接的未访问的顶点的前驱顶点记录下来,以便输出时回溯。 #include int number //队列类型 typedef struct{ int q[20] -[imported] map of the number of vertices N, Vertex map of the relationship between the starting point and end point A and B [output] if A to B without path then exporting "There is no path" Otherwise output A to B on the path vertices [storage structure] plan adopted adjacency matrix of storage. [Algorithm for the basic idea] BFS way from the vertex A, A visit followed with adjacent vertices VA1, VA2 ,..., VAK, visiting times, if not visit B, continue to visit with the VA1 adjacent vertices VA11, VA12 ,..., VA1M. VA2 and then

下载说明:请别用迅雷下载,失败请重下,重下不扣分!

发表评论

0 个回复

  • 双向约瑟夫问题
    约瑟夫问题是一个经典的问题,我们不妨将这个经典问题进行扩展,变成一个双向的约瑟夫问题。 已知n个人(不妨分别以编号1,2,3,…,n 代表 )围坐在一张圆桌周围,首先从编号为 k 的人从1开始顺时针报数,1, 2, 3, ...,记下顺时针数到 m 的那个人,同时从编号为 k 的人开始逆时针报数,1, 2, 3, ...,数到 m 后,两个人同时出列。然后从出列的下一个人又从 1 开始继续进行双向报数,数到m的那两个人同时出列,…;。依此重复下去,直到圆桌周围的人全部出列。直到圆桌周围只剩一个人为止。    如果双向报数报到 m 时落在同一个人身上,那本次出列的只有一个人。 请点击左侧文件开始预览 !预览只提供20%的代码片段,完整代码需下载后查看 加载中 侵权举报
    2022-02-15 10:54:04下载
    积分:1
  • for liquid simulation study cfd a new method, boltzmann called the lattice metho...
    用于液体模拟,是研究cfd的一种新方法,称之为lattice boltzmann方法。本程序是d105模型的编码。这类编码网上很少,几近没有。如果哪们朋友有这方面的还希望能共用-for liquid simulation study cfd a new method, boltzmann called the lattice method. The procedure is d105 model coding. Few of these online coding, there was virtually no. If what they have friends in this area also hope to share
    2023-02-04 14:20:03下载
    积分:1
  • 酒店时钟源码
    应用背景  定义一个类Clock 属性有hour、minute、second 功能有display(显示时间)、set(设置时间)和tick(走一秒) 为Clock添加静态成员count,并初始化,在测试代码中先后声明两个钟 2、类的组合:定义Time类,定义Clock2,属性为Time型变量time 3、(从1中)派生一个类HotelClock 属性有hour、minute、second、city(注意:属性继承v.s.新增) 功能有display、set和tick(注意:哪些功能需要重写) 测试代码中声明一个长度为3的HotelClock数组,分别存北京、东京(比北京晚1个小时)和纽约时间(比北京早15个小时),并输出。 4、为HotelClock类重载
    2023-04-03 23:50:04下载
    积分:1
  • 无尽ssd6的最后验证
    资源描述ASD的广告asasd广告广告广告广告asasd asasd asasd asasd广告广告广告广告asasd asasd asasd asasd广告广告广告广告asasd asasd asasd asasd广告广告广告广告asasd asasd asasd asasd广告广告广告广告asasd asasd asasd asasd广告广告广告广告asasd asasd asasd asasd广告广告广告广告asasd asasd asasd asasd asasd asasd广告广告广告asasd广告广告广告广告asasd asasd asasd asasd广告
    2023-02-27 05:00:03下载
    积分:1
  • 让系统启动时运行某个应用程序
    让系统启动时运行某个应用程序-let activated a running application
    2023-01-18 07:15:04下载
    积分:1
  • 使用pb备份sqlserver数据库
    使用pb备份sqlserver数据库-use SQLServer database backup pb
    2023-06-18 15:55:03下载
    积分:1
  • 用asp来实现 附件功能计算,很好用,没有错误! 但还请各位专家给与指正! 谢谢!...
    用asp来实现 附件功能计算,很好用,没有错误! 但还请各位专家给与指正! 谢谢!-used to achieve attachments, useful, no mistake! But also asked the experts to give correct! Thank you!
    2022-01-25 18:04:27下载
    积分:1
  • 50个C#的完整源代码,比较适合初学者自学使用
    50个C#的完整源代码,比较适合初学者自学使用-50 C# the complete source code, more suitable for beginners learning to use
    2022-03-30 10:15:00下载
    积分:1
  • iso_iec_14496
    ISO_IEC_14496-1_2001(E)标准-ISO_IEC_14496- 1_2001 (E) standards
    2022-07-02 18:44:53下载
    积分:1
  • 初学者们,为指针而困惑吗?读这个文件吧!里面对指针分析和比较的比较详细了!类型很多,请在清醒的情况下阅读,否则会越读越模糊。...
    初学者们,为指针而困惑吗?读这个文件吧!里面对指针分析和比较的比较详细了!类型很多,请在清醒的情况下阅读,否则会越读越模糊。-Beginners were confused as a guideline and it? Reading this document now! Inside of the pointer analysis and a more detailed comparison of the! Many types in a clear case of reading, otherwise they will be more read more fuzzy.
    2023-02-09 03:30:04下载
    积分:1
  • 696518资源总数
  • 106148会员总数
  • 10今日下载