for(int nbr:l[node]){
if(!visited[nbr]){
q.push(nbr);
//mark that nbr as visietd
visited[nbr]=true;
}
}
How iterator is working in this BFS traversal
Hey if you are asking how exactly for(int nbr:l[node]) then this a short method provided in later versions of c++ to traverse over data containers/arrays and it also saves some time otherwise you have to write like this
for (std::vector::iterator it = v.begin(); it != v.end(); ++it)
For more details go check this : https://www.bogotobogo.com/cplusplus/C11/C11_Type_Inference_auto_range_based_for_loop.php
If this is not what you have asked then please elaborate.
I hope I’ve cleared your doubt. I ask you to please rate your experience here
Your feedback is very important. It helps us improve our platform and hence provide you
the learning experience you deserve.
On the off chance, you still have some questions or not find the answers satisfactory, you may reopen
the doubt.