代码:
void BFS ( LGraph Graph, Vertex S, void (*Visit)(Vertex) )
{
int queue[105],front=-1,rear=-1;//一个节点最多有9个邻接点,10*9=90<105遍历一趟绝对够用,所以不用循环数组
queue[++rear]=S;
Visited[S]=true;
PtrToAdjVNode temp;
while(front!=rear)
{
int u=queue[++front];
Visit(u);
temp=Graph->G[u].FirstEdge;
while(temp)
{
if(!Visited[temp->AdjV])//节点未被访问
{
Visited[temp->AdjV]=true;//设为已访问
queue[++rear]=temp->AdjV;
}
temp=temp->Next;
}
}
return ;
}
限制只能使用C语言好难受啊。。。还得手搓一个队列出来。。。