daily pastebin goal
75%
SHARE
TWEET

Untitled

a guest Jan 22nd, 2018 65 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
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top