Kulesh

bfs

Dec 23rd, 2016
95
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.47 KB | None | 0 0
  1. void bfs(int i){
  2. for(int j = 0; j < 9; j++){
  3. visited[j] = 0;
  4. parent.push_back(-1);
  5. }
  6. queue<int> Q;
  7. visited[i] = 1;
  8. Q.push(i);
  9.  
  10. while(Q.size() != 0){
  11. int a = Q.front();
  12. Q.pop();
  13. for(int k = 0; k < E[a].size(); k++) {
  14. int s = E[a][k];
  15. if(visited[s] == 0){
  16. visited[s] = 1;
  17. parent[s] = a;
  18. Q.push(s);
  19. }
  20. }
  21. }
  22. }
Add Comment
Please, Sign In to add comment