图的深搜与广搜

typedef char VType;
#define INF 65535
#define MAXVEX 100
//邻接矩阵 
typedef struct{
	VType vertices[MAXVEX];
	int edges[MAXVEX][MAXVEX];
	int vexnum,edgenum;
}MGraph; 
//邻接表
typedef struct ENode{
	int adjvex;
	struct ENode *next;
}ENode;
typedef struct VNode{
	VType data;
	ENode *firstedge;
}VNode,AdjList[MAXVEX];
typedef struct{
	AdjList vertices;
	int vexnum,edgenum;
}ALGraph;

//邻接矩阵深搜 
bool vis[MAXVEX];
void DFStraverse(MGraph G){
	for(int i=0;iadjvex]){
				printf("%c",G.vertices[p->adjvex].data);
				vis[p->adjvex]=true;
				EnQueue(Q,p->adjvex);
			}
			p=p->next; 
		}
	}
}

int d[MAXVEX];
void BFS_MIN_Distance(MGraph G,int u){
	for(int i=0;i

 

你可能感兴趣的:(图的深搜与广搜)