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()){
- int next = vi.next();
- if(!visited[next]){
- System.out.print(next + " ");
- q.add(next);
- visited[next] = true;
- }
- }
- }
- }
Add Comment
Please, Sign In to add comment