当前位置:网站首页>Implementation of depth traversal adjacency matrix of figure 6-5
Implementation of depth traversal adjacency matrix of figure 6-5
2022-06-22 21:55:00 【White -】
6-5 Depth traversal of Graphs - Adjacency matrix implementation
This problem requires the realization of depth first traversal of adjacency matrix storage graph .
Function interface definition :
void DFS(MGraph G,Vertex v);
among MGraph Is a graph stored in adjacency matrix , The definition is as follows :
#define MaxVertexNum 10 / Define the maximum number of vertices /
typedef int Vertex;/* Use vertex subscript to represent vertex , Is an integer */
typedef struct{
int arcs[MaxVertexNum][MaxVertexNum]; / Adjacency matrix /
int vexnum,arcnum; / Number of vertices in the graph vexnum And the number of sides arcnum/
}MGraph; / Types of graphs represented by adjacency matrix /
Sample referee test procedure :
#include"stdio.h"
#include"stdlib.h"
typedef enum{FALSE,TRUE} Boolean;
#define MaxVertexNum 10 / Define the maximum number of vertices /
typedef int Vertex;/* Use vertex subscript to represent vertex , Is an integer /
typedef struct{
int arcs[MaxVertexNum][MaxVertexNum]; / Adjacency matrix /
int vexnum,arcnum; / Number of vertices in the graph vexnum And the number of sides arcnum/
}MGraph; / Types of graphs represented by adjacency matrix /
Boolean visited[MaxVertexNum]; / Access token for vertex */
void CreatMGraph(MGraph G);/ Create a diagram and add Visited Initialize to false; The referee realizes , Details don't show /
void DFS(MGraph G,Vertex v);
int main()
{
Vertex v;
MGraph G;
CreatMGraph(&G);
scanf(“%d”, &v);
printf(“DFS from %d:”,v);
DFS(G,v);
return 0;
}
/ Your code will be embedded here */
For a given graph :
sample input :
The first line gives the number of vertices of the graph n And the number of sides e, And then e That's ok , Each row gives two vertex numbers for an edge , The last line gives the starting vertex number of the traversal .
7 9
0 2
0 3
0 4
1 3
1 5
2 3
2 5
4 5
5 6
5
sample output :
DFS from 5: 5 1 3 0 2 4 6
Code :
void DFS(MGraph G,Vertex v)
{
visited[v] = 1;
printf(" %d",v);
for(int i = 0; i < G.vexnum ; i++)
if(G.arcs[v][i] ==1 && !visited[i])
DFS(G, i);
return;
}
202206201636 One
边栏推荐
- What is a data asset? How should data asset management be implemented?
- 7-1 前序序列创建二叉树
- 鸿蒙第三次培训
- 数据科学家是不是特有前途的职业?
- Lesson 029: Documents: a task? After class test questions and answers
- Redis usage scenario sharing (project practice)
- 长安旗下阿维塔科技增资扩股落定:宁德时代将持股约24%!
- Android kotlin SP DP to PX
- Jerry's music mode obtains the directory of playing files [chapter]
- [book delivery at the end of the article] AI has spread all over the Internet to color old photos. Here is a detailed tutorial!
猜你喜欢

Lesson 014-15: string (see lesson 27-32 of the new version of little turtle) | after class test questions and answers

校园跑腿管理端APP—陕西格创
![DACL output on Jerry's hardware, DAC output sound of left and right channels [chapter]](/img/8a/ce164a5538bd8edf10eba5e4e8abe6.png)
DACL output on Jerry's hardware, DAC output sound of left and right channels [chapter]

6-5 图的深度遍历-邻接矩阵实现
![Jerry's plug-in 4m flash to view the processing method with a size of only 1m on the PC [chapter]](/img/8a/49b23eb63ff7e8814d1d49282c9fa2.png)
Jerry's plug-in 4m flash to view the processing method with a size of only 1m on the PC [chapter]

杰理之列免晶振一拖八烧录升级【篇】
![[513. find the value in the lower left corner of the tree]](/img/6d/b2ec8e3072a65c20c586941e6b2a85.png)
[513. find the value in the lower left corner of the tree]

TC397 Flash

Capital and share increase of avita technology under Chang'an is settled: Ningde times will hold about 24%!

300. 最长递增子序列 ●●
随机推荐
Cannot re register id: pommeffacompetition-v0 problem solving
Lesson 031: permanent storage: pickle a jar of delicious pickles | after class test questions and answers
大势智慧创建倾斜模型和切割单体化
第019讲:函数:我的地盘听我的 | 课后测试题及答案
300. 最长递增子序列 ●●
Redis usage scenario sharing (project practice)
Introduce sparse activation mechanism! Uni perceiver MOE significantly improves the performance of generalist model
第029讲:文件:一个任务 | 课后测试题及答案
Optimization solver | gurobi's Mvar class: a sharp tool for matrix modeling and an alternative solution to dual problems (with detailed cases and codes attached)
Cannot re-register id: PommeFFACompetition-v0问题解决
6-6 图的广度遍历-邻接矩阵实现
Summary of differences between localstorage, sessionstorage and cookies
6-3 二叉树的非递归遍历
第016讲:序列 | 课后测试题及答案
7-9 超级玛丽
Ten thousand words long text | use RBAC to restrict access to kubernetes resources
84- I am on Internet & lt; 52 SQL statement performance optimization strategies & gt; Some views of
PHP image making
Redis的使用场景分享(项目实战)
las 点云创建网格