Advertisement
Guest User

Untitled

a guest
Oct 14th, 2019
80
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.35 KB | None | 0 0
  1.  
  2. void bfs(int s, vector<int> adj[], bool vis[], int N)
  3. {
  4.  
  5. queue<int> q;
  6. q.push(s);
  7. while(!q.empty()){
  8. int top =q.front();
  9. for (auto x : adj[top])
  10. if (!vis[x])
  11. q.push(x);
  12. cout << top << ' ';
  13. vis[top] = true;
  14. q.pop();
  15. }
  16. cout << endl;
  17.  
  18.  
  19. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement