如何判断有向图是否存在环路?图是用邻接矩阵来存储的

1个回答

  • #include"utility.h"

    #include"adj_matrix_undir_graph.h"

    #include"adj_list_dir_graph.h"

    #include"dfs.h"

    #include"bfs.h"

    int main(void)

    {

    x09int n,j=0,i=0;

    x09int m,e,b=0;

    x09char vexs[20],c;

    x09char nums[20];

    x09cout>n;

    x09cout

    x09{

    x09x09cout>vexs[i];

    x09x09j++;

    x09}

    x09

    x09cout

    aundir(vexs,n);

    x09for(i=0;i

    x09{

    x09x09for(int v=1;v

    x09x09{

    x09x09x09cout>c;

    x09x09x09if(c == 'Y' )

    x09x09x09x09aundir.InsertEdge(i,v);

    x09x09}

    x09}

    x09Display(aundir);

    x09

    x09cout>m;

    x09for(int a=0;a

    x09{

    x09x09cout>nums[a];

    x09x09b++;

    x09}

    x09AdjListDirGraph

    dir(nums,m);

    for(int k=0;k

    x09{

    x09x09for(e=0;e

    x09x09{

    x09x09x09cout>c;

    if(c == 'Y' )

    x09x09x09x09dir.InsertEdge(k,e);

    x09x09}

    x09}

    x09Display(dir);

    x09cout

    (aundir,Write

    );

    x09cout<

    x09cout< BFSTraverse

    (aundir,Write

    );

    x09

    x09cout<

    x09cout

    (dir,Write

    );

    x09cout<

    x09cout< BFSTraverse

    (dir,Write

    );