【发布时间】:2012-12-30 12:17:57
【问题描述】:
我有一组节点和几条边来表示哪些节点是连接的。 V_nodes 1 7 22 97 48 11 V_arcs (1 22) (97 22) (7 1) (11 48) (48 7) (11 0) V_weight 1
我已经创建了它的邻接矩阵,其中 1 表示连接的顶点,0 表示断开的顶点。 现在我想使用它的邻接矩阵为这个图实现深度优先遍历。 我已经看过关于 DFS 的教程,但我很困惑如何使用我的邻接矩阵遍历它。 我只需要使用深度优先遍历来打印节点。 任何帮助将不胜感激。
// Prints the adjacency matrix
cout<<"Adjacency Matrix : \n";
for(int i=0;i<6;i++)
cout<<" "<<nodes[i].nodevalue;
cout<<endl<<endl;
for(int i=0;i<6;i++)
{
for (int j=0;j<6;j++)
{
cout<<" "<<edges[i][j];
}
cout<<endl<<nodes[i].nodevalue;
cout<<endl<<endl;
}
【问题讨论】:
标签: c++ graph traversal depth-first-search adjacency-matrix