Guest User

Untitled

a guest
Jan 22nd, 2018
71
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.51 KB | None | 0 0
  1. private void breadthFirstSearch(UndirectedGraph g, int a, boolean[] visited){
  2. Queue<Integer> q = new LinkedList<Integer>();
  3. visited[a] = true;
  4. q.add(a);
  5. System.out.print(a + " ");
  6. while(!q.isEmpty()){
  7. int x = q.remove();
  8. VertexIterator vi = g.adjacentVertices(x);
  9. while(vi.hasNext()){
  10. int next = vi.next();
  11. if(!visited[next]){
  12. System.out.print(next + " ");
  13. q.add(next);
  14. visited[next] = true;
  15. }
  16. }
  17. }
  18. }
Add Comment
Please, Sign In to add comment