0
所以这是算法即时通讯使用,我想知道在哪个级别的深度我使用BFS如何知道我在使用BFS(广度优先搜索)的搜索级别?
void bfs(int n)
{
vis[n]=1; //marks n visited
d=0;
while(!adj[n].empty()) //adj is the array containing the adjacency lists
{if(!(vis[adj[n].front()]))
{
q.push(adj[n].front()); //q is the queue
}
adj[n].pop_front();
}
if(!q.empty()){
n=q.front();
cout<<n<< "->";
q.pop();
bfs(n);
}
}
我能做些什么?
沿着一个额外的'depth'参数只是传递。在初次调用'bfs'时,传递0。在递归调用中,传递'depth + 1'。因此:'void bfs(int n,int depth){... bfs(n,depth + 1); '' –