Advertisement

数据结构中的图论中的深度优先搜索(DFS)和广度优先搜索(BFS)主要采用的是两种不同的遍历方式

阅读量:

一、基于邻接矩阵的深度优先搜索递归遍历方法

复制代码
 /*

    
 Author: luuuuyang
    
 Date: 2018/11/1
    
 Version 1.0
    
 Functions:创建无向网络邻接矩阵即带权无向图+递归DFS遍历 
    
 */
    
 #include<iostream>
    
 #include<cstring>
    
 using namespace std;
    
 #define MaxInt 32767//表示无穷大(大于任何权值) 
    
 #define MVnum 100 //Max Vertex Number 
    
 typedef char VertexType;//顶点数据类型 
    
 typedef int ArcType;//权值数据类型 
    
 typedef struct{
    
 	VertexType vexs[MVnum];//保存顶点的数组 
    
 	ArcType arcs[MVnum][MVnum];//arcs[i][j]=w 
    
 	int vexnum,arcnum;//顶点数;边数 
    
 }AMGraph;
    
 int LocateVex(AMGraph G,VertexType v){/

全部评论 (0)

还没有任何评论哟~