用C或者C++编程,建立一个无向图的邻接矩阵或邻接表,实现该图的深度或广度优先搜索。

如题所述

第1个回答  2015-06-10
我有现成的,等明天给你追答

#include #include #include #define MAX 90000 using namespace std; class AdjMatrix {public: int n; int matrix[101][101]; int weight[101]; void CreatGraph(int num,int m); void DFSTraverse(int v1,int v2); void DFS(int v1,int v2,int visited[]); int FirstAdjVex(int v); int NextAdjVex(int v,int w); void Searchweight(); }; void AdjMatrix::Searchweight() { memset(weight,0,sizeof(weight)); int i,j; for(i=0;i>row>>col; matrix[row-1][col-1]=1; } Searchweight(); } int AdjMatrix::FirstAdjVex(int v) { for(int i=0;i>n>>m; AdjMatrix *G=new AdjMatrix; G->CreatGraph(n,m); for(int i=0;in;i++) coutweight[i]>v1>>v2; v1-=1;v2-=1; G->DFSTraverse(v1,v2); cout<<"0\n"; }

可能有点乱,给你个链接 http://pan.baidu.com/share/link?shareid=3766021313&uk=1143990708

相似回答