数据结构 图的操作 40
Input:thenumberofvertex,thenumberofedge,alledges(Vi,Vj)anditsweightinagraph.Output:(1...
Input: the number of vertex, the number of edge, all edges (Vi,Vj) and its weight in a graph.
Output:
(1).print the graph.
(2).print the sequence of vertex names getting from Depth-First Search.
(3). print the sequence of vertex names getting from Breadth-First Search.
For example (See Figure 1):
Input:
6 11 // indicate the graph including six vertexes and eleven edges.
0 1 50 // indicate an edge from V0 to V1.
0 2 10
0 4 45
1 2 15
1 4 10
2 0 20
2 3 15
3 1 20
3 4 35
4 3 30
5 3 3
Figure 2
Output:
0:1 2 4
1:2 4
2:0 3
3:1 4
4:3
5:3
The sequence of vertex names getting from Depth-First Search (from ‘V1’):
V1 V2 V0 V4 V3 V5
The sequence of vertex names getting from Breadth-First Search (from ‘V1’):
V1 V2 V4 V0 V3 V5
Shortest paths from v0 to each vertex are
V0 to V1 45
V0 to V2 10
V0 to V3 25
V0 to V4 45
V0 to V5 1000
(“1000” means no path.)
有向图 展开
Output:
(1).print the graph.
(2).print the sequence of vertex names getting from Depth-First Search.
(3). print the sequence of vertex names getting from Breadth-First Search.
For example (See Figure 1):
Input:
6 11 // indicate the graph including six vertexes and eleven edges.
0 1 50 // indicate an edge from V0 to V1.
0 2 10
0 4 45
1 2 15
1 4 10
2 0 20
2 3 15
3 1 20
3 4 35
4 3 30
5 3 3
Figure 2
Output:
0:1 2 4
1:2 4
2:0 3
3:1 4
4:3
5:3
The sequence of vertex names getting from Depth-First Search (from ‘V1’):
V1 V2 V0 V4 V3 V5
The sequence of vertex names getting from Breadth-First Search (from ‘V1’):
V1 V2 V4 V0 V3 V5
Shortest paths from v0 to each vertex are
V0 to V1 45
V0 to V2 10
V0 to V3 25
V0 to V4 45
V0 to V5 1000
(“1000” means no path.)
有向图 展开
2个回答
展开全部
1.
按邻接矩阵创建图(包括无向图/无向网)
CreateGraph
2.
求无向图的深度优先遍历和广度优先遍历
DFSTraverse
BFSTraverse
3.
求输出无向网的最小生成树(Prim和Kruskal算法都可以)
MST_Prim
MST_Kruskal
数据结构很重要,尤其是编程思想。
www.onwit.cn
我个人站点。
按邻接矩阵创建图(包括无向图/无向网)
CreateGraph
2.
求无向图的深度优先遍历和广度优先遍历
DFSTraverse
BFSTraverse
3.
求输出无向网的最小生成树(Prim和Kruskal算法都可以)
MST_Prim
MST_Kruskal
数据结构很重要,尤其是编程思想。
www.onwit.cn
我个人站点。
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
美林数据技术股份有限公司
2019-06-26 广告
2019-06-26 广告
美林数据Tempo大数据分析平台,它是一款集数据接入、数据处理、数据挖掘、数据可视化、数据应用于一体的软件产品。它秉持“智能、互动、增值”的设计理念,面向企业级用户提供自助式数据探索与分析能力,为企业提供从BI到AI的一体化数据分析与应用解...
点击进入详情页
本回答由美林数据技术股份有限公司提供
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询