图深度优先搜索DFS(邻接矩阵)C/C++

#include <bits/stdc++.h>
using namespace std;

typedef char VertexType;
typedef int EdgeType;
struct GraphStruct;
typedef struct GraphStruct *Graph;
struct GraphStruct{
    VertexType vexs[100];
    EdgeType edge[100][100];
    int visited[100];
    int vertexnum;
    int edgenum;
}; 

Graph CreateGraph()
{
    Graph g=(Graph)malloc(sizeof(struct GraphStruct));
    g->vertexnum=0;
    g->edgenum=0;
    return g;
}

void DFS(Graph g,int k)
{
    g->visited[k]=1;
    for(int i=0;i<g->vertexnum;i++)
        if(g->edge[k][i]==1 && g->visited[i]==0)
            DFS(g,i);

猜你喜欢

转载自blog.csdn.net/linyuan703/article/details/81288829