daily pastebin goal
40%
SHARE
TWEET

Untitled

a guest Jan 22nd, 2018 64 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  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.     }
RAW Paste Data
Top