[英]How do I create a queue of traversed vertex using boost graph library breadth-first search?
[英]how do i know on which level of search am i using BFS (Breadth-first search)?
所以這是我正在使用的算法,我想知道我在使用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);
}
}
我能做什么?
為了知道您現在的深度,您應該考慮添加額外的array depth 。 深度大小等於圖形中的頂點數,並且包含每個頂點的深度(從您開始BFS的頂點開始計算)。 遍歷父級的子級時,應將深度 [子級] = 深度 [父級] + 1
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.