无向图的深度优先遍历
voidDFS(graph*g,inti){intj;intvisited[n];for(j=0;j<n;j++)visited[j]=0;printf("node:%c...
void DFS (graph *g, int i )
{ int j ; int visited[n];
for ( j = 0; j< n; j++ )
visited [j] = 0;
printf("node:%c\n",g->vexs[i]);
visited[i]=1;
for ( j= 0; j<n; j++ )
if (g->arcs[i][j]==1&&( ! visited[j] ))
DFS (g,j);
}
介个函数好像不对,结果是两个结点无限交替输出,请问错在哪? 展开
{ int j ; int visited[n];
for ( j = 0; j< n; j++ )
visited [j] = 0;
printf("node:%c\n",g->vexs[i]);
visited[i]=1;
for ( j= 0; j<n; j++ )
if (g->arcs[i][j]==1&&( ! visited[j] ))
DFS (g,j);
}
介个函数好像不对,结果是两个结点无限交替输出,请问错在哪? 展开
1个回答
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询