Guest User

Untitled

a guest
Jan 22nd, 2018
98
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.50 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. if(!visited[vi.next()]){
  11. System.out.print(vi.next() + " ");
  12. q.add(vi.next());
  13. visited[vi.next()] = true;
  14. }
  15. }
  16. }
  17. }
Add Comment
Please, Sign In to add comment