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 + " ");
- VertexIterator vi = g.adjacentVertices(a);
- while(!q.isEmpty()){
- int x = q.remove();
- if(vi.hasNext()){
- if(visited[vi.next()]){
- System.out.print(vi.next() + " ");
- breadthFirstSearch(g, vi.next(), visited);
- }
- }
- }
- }
Add Comment
Please, Sign In to add comment