邻接矩阵存储图的深度优先遍历 的部分代码

typedef struct GNode* PtrToGNode;
typedef PtrToGNode MGraph; /* 以邻接矩阵存储的图类型 */
bool Visited[MaxVertexNum]; /* 顶点的访问标记 */
struct GNode {
    int Nv;  /* 顶点数 */
    int Ne;  /* 边数   */
    WeightType G[MaxVertexNum][MaxVertexNum]; /* 邻接矩阵 */
};

void DFS(MGraph Graph, Vertex V, void (*Visit)(Vertex)) {
    Vertex i;
    Visited[V] = 1;
    Visit(V);

    for (i = 0; i < Graph->Nv; i++)
        if (Graph->G[V][i] == 1 && !Visited[i])
            DFS(Graph, i, Visit);

    return;
}
void Visit(Vertex V) { printf(" %d", V); }

MGraph CreateGraph(); /* 创建图并且将Visited初始化为false */
/*主要是邻接矩阵和邻接表两种,邻接矩阵主要是看相邻得两个顶点之间是否有边*/
原文地址:https://www.cnblogs.com/letianpaiai/p/12849201.html