当前位置:网站首页>Implementation of breadth traversal adjacency matrix of 6-6 graph
Implementation of breadth traversal adjacency matrix of 6-6 graph
2022-06-22 21:55:00 【White -】
6-6 Breadth traversal of graph - Adjacency matrix implementation
This problem requires the realization of breadth first traversal of adjacency matrix storage graph .
Function interface definition :
void BFS(MGraph G,Vertex i);
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 BFS(MGraph G,Vertex v);
int main()
{
Vertex v;
MGraph G;
CreatMGraph(&G);
scanf(“%d”, &v);
printf(“BFS from %d:”,v);
BFS(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 :
BFS from 5: 5 1 2 4 6 3 0
Code :
void BFS(MGraph G,Vertex v)
{
int que[105];
int front=0;
int rear=0;
printf(" %d",v);
visited[v] = TRUE;
que[rear++] = v;
while(rear!=front)
{
int u = que[front++];
for(int i = 0 ;i < G.vexnum ;i ++)
{
if(!visited[i]&&G.arcs[u][i]==1)
{
printf(" %d",i);
visited[i] = TRUE;
que[rear++] = i;
}
}
}
}
202206201637 One
边栏推荐
- 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)
- 不同网络结构的特征也能进行对比学习?蚂蚁&美团&南大&阿里提出跨架构自监督视频表示学习方法CACL,性能SOTA!
- The problem that Jericho can't play the prompt tone in the music mode using the interrupt mode [chapter]
- LeetCode#20. Valid parentheses
- 第025讲:字典:当索引不好用时 | 课后测试题及答案
- 杰理之使用 DP 和 DM 做 IO 按键检测注意点【篇】
- Lesson 031: permanent storage: pickle a jar of delicious pickles | after class test questions and answers
- 79- do not create desc descending index when you see order by XXX desc - there is book donation benefit at the end of the article
- Lesson 029: Documents: a task? After class test questions and answers
- 【ICML2022】利用虚拟节点促进图结构学习
猜你喜欢

Lesson 019: function: my site listen to my after-school test questions and answers

Laravel+ pagoda planning task
![[book delivery at the end of the article] AI has spread all over the Internet to color old photos. Here is a detailed tutorial!](/img/f0/4f237e7ab1bff9761b6092dd4ef3d9.png)
[book delivery at the end of the article] AI has spread all over the Internet to color old photos. Here is a detailed tutorial!
![When the AUX1 or aux2 channel is used in Jerry's aux mode, the program will reset the problem [chapter]](/img/0a/93e95a3a2a923497d57895508ce92e.png)
When the AUX1 or aux2 channel is used in Jerry's aux mode, the program will reset the problem [chapter]

优化求解器 | Gurobi的MVar类:矩阵建模利器、求解对偶问题的备选方案 (附详细案例+代码)

Research hotspot - Official publicity! The release time of JCR zoning and impact factors will be determined in 2022!

300. 最长递增子序列 ●●

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)

分享insert into select遇到的死锁问题(项目实战)
![Jerry's dynamic switching EQ document [chapter]](/img/2d/9a0245b87fb05ea61dbfc7922ea766.png)
Jerry's dynamic switching EQ document [chapter]
随机推荐
为了不曾忘却的纪念:孙剑专题
ACM. HJ45 名字的漂亮度 ●●
DACL output on Jerry's hardware, DAC output sound of left and right channels [chapter]
Laravel+ pagoda planning task
ByteDance proposes a lightweight and efficient new network mocovit, which has better performance than GhostNet and mobilenetv3 in CV tasks such as classification and detection
The necessary materials for the soft test have been released. All the soft test materials for the whole subject have been prepared for you!
鸿蒙第三次培训
2022年6月25日PMP考试通关宝典-6
引入稀疏激活机制!Uni-Perceiver-MoE显著提升通才模型的性能
杰理之外挂 4M 的 flash 在 PC 上查看大小只有 1M 的处理方法【篇】
PHP image making
75- when left join encounters subquery
IDC publie le rapport sur la gouvernance des données en Chine
(duc/ddc) digital up mixing / quadrature down mixing principle and MATLAB simulation
数据科学家是不是特有前途的职业?
7-1 前序序列创建二叉树
Lesson 020: functions: embedded functions and closures | after class test questions and answers
Differences between watch, computed and methods
Is data scientist a promising profession?
杰理之AUX 模式使用 AUX1或者 AUX2通道时,程序会复位问题【篇】