邻接表建图+深度遍历+判断连通性
来源:互联网 发布:java程序员考证 编辑:程序博客网 时间:2024/06/06 03:59
#include<stdio.h>#include<stdlib.h>#define Max 10typedef struct Node{ int ver; struct Node*next;}VexNode;struct Adj{ VexNode*next;}; Adj adj[Max];int visit[Max];void depth(int start){ printf("%d ",start); visit[start]=1; VexNode *p; p=adj[start].next; while(p!=NULL) { int v=p->ver; if(!visit[v]) depth(v); p=p->next; }}void InitMap(Adj adj[],int numN){ for(int i=1;i<=numN;i++) adj[i].next=NULL;}void CreatMap(Adj adj[],int numB){ for(int i=0;i<numB;i++){ int a,b; scanf("%d%d",&a,&b); VexNode*q; q=(VexNode*)malloc(sizeof(VexNode)); q->ver=b; q->next=adj[a].next; adj[a].next=q; VexNode*q1; q1=(VexNode*)malloc(sizeof(VexNode)); q1->ver=a; q1->next=adj[b].next; adj[b].next=q1; }} int iscon(Adj adj[],int numN){ for(int i=1;i<=numN;i++) if(!visit[i]) return 0; return 1;} int main() { int numN,numB; scanf("%d%d",&numN,&numB); InitMap(adj,numN); CreatMap(adj,numB); depth(1); //1为开始遍历的点 printf("%s\n",iscon(adj,numN)==1?"是连通图":"不是联通图!"); return 0;}
0 0
- 邻接表建图+深度遍历+判断连通性
- leetcode 684. Redundant Connection 邻接表的环的判断 + 深度优先遍历DFS
- 图: 广度深度优先遍历(邻接表)
- 图的深度遍历-邻接表
- 邻接表的实现与深度遍历
- 基于邻接表的深度优先遍历
- 图---邻接表(建立,深度遍历,广度遍历)
- 图——邻接表(深度遍历,广度遍历)
- 邻接表深度优先遍历和广度遍历
- 邻接表-图的遍历-广度和深度优先遍历
- 图---邻接表(建立,深度遍历,广度遍历)
- 图---邻接表(建立,深度遍历,广度遍历)
- 邻接图的广度优先遍历和深度优先遍历
- 图---邻接表(建立,深度遍历,广度遍历)
- 图的深度遍历和广度遍历--邻接链表法
- 深度遍历和广度遍历,邻接表和邻接矩阵
- 邻接表的深度优先遍历以及广度优先遍历
- 图的邻接表存储与深度优先遍历算法
- eclipse导入本地插件的方法
- 单词统计
- Python Flask Web 第五课 —— 包含导航条的程序基模板
- Animation.setFillAfter 是什么意思呢
- 斗鱼TV、熊猫TV移动端竞品分析
- 邻接表建图+深度遍历+判断连通性
- 编程命名规则
- scanf读取数值类型数据会在缓冲区中留下'\n'
- JDBC应用程序连接数据库--事务处理
- leetcode-28-Implement strStr()
- idea自动生成junit测试代码配置
- 负值之美:负margin在页面布局中的应用
- B - Xiper的奇妙历险(2)
- Inheritance继承