Guest User

Untitled

a guest
Jan 22nd, 2018
88
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.48 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. VertexIterator vi = g.adjacentVertices(a);
  7. while(!q.isEmpty()){
  8. int x = q.remove();
  9. if(vi.hasNext()){
  10. if(visited[vi.next()]){
  11. System.out.print(vi.next() + " ");
  12. breadthFirstSearch(g, vi.next(), visited);
  13. }
  14. }
  15. }
  16. }
Add Comment
Please, Sign In to add comment