//深度优先搜索(Depth-First-Search,DFS)
//类似于先序遍历,采用递归算法实现
bool visited[MAX_VERTEX_NUM]
void DFSTraverse(Graph G)
{
for(i = 0;i<G.vexnum;++i)
{
visited[i] = false;
}
for(i = 0;i < G.vexnum ;++i)
{
if(visited[i] == false)
DFS(G,i);
}
}
void DFS(Graph G,int i)
{
visit(i);
visited[i] = true;
for(w = FirstNieghbor(G,i); i>=0; w =NextNeighbor(G,i,w))
{
if(!visited[w])
DFS(G,w);
}
}
深度优先搜索(Depth-First-Search,DFS)
最新推荐文章于 2023-12-04 23:51:36 发布