如何判断无向图是否存在回路?
bool Judgeloop(Graphm* G, int v){
int w;
G->setMark(v, VISITED);
if(G->getMark(G->n()) == VISITED)
{
cout<<"fd"<<endl;
return false;
}
for (w=G->first(v); w<G->n();w = G->next(v,w))
{
if (G->getMark(w) == UNVISITED)
Judgeloop(G, w);
if(G->getMark(w) == VISITED&&v>w)
{
return true;
}
}
}这是我的代码,请问有什么问题?
求高手给一份正确的代码