我尝试了 cormen 为 bfs 指定的算法,
代码是:
bfs(int s){
int i;
int u,v;
struct edge *e;
graph[s].colour=1;
graph[s].d=0;
graph[s].pre=-1;
enqueue(s);
while (isempty()!=1){
u=dequeue();
printf("%d\t",u);
e=graph[u].edgePtr;
while(e!=NULL)
{
v=e->vertexIndex;
if(graph[v].colour==WHITE){
graph[v].colour=GRAY;
graph[v].d=graph[u].d+1;
graph[v].pre=u;
enqueue(v);
e=e->edgePtr;
}
graph[u].colour=BLACK;
}
}
}
我得到一个无限循环......有人能告诉我我到底哪里出错了吗?