Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- private void breadthFirstSearch(UndirectedGraph g, int a, boolean[] visited){
- Queue<Integer> q = new LinkedList<Integer>();
- visited[a] = true;
- q.add(a);
- System.out.print(a + " ");
- while(!q.isEmpty()){
- int x = q.remove();
- VertexIterator vi = g.adjacentVertices(x);
- while(vi.hasNext()){
- if(!visited[vi.next()]){
- System.out.print(vi.next() + " ");
- q.add(vi.next());
- visited[vi.next()] = true;
- }
- }
- }
- }
Add Comment
Please, Sign In to add comment