Skip to content

Instantly share code, notes, and snippets.

@hilda8519
Created July 9, 2014 23:19
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save hilda8519/ddf4f88a839401471697 to your computer and use it in GitHub Desktop.
Save hilda8519/ddf4f88a839401471697 to your computer and use it in GitHub Desktop.
import java.util.*;
public class checkRoute {
public void bfs()
{
public static rootNode;
// BFS uses Queue data structure
Queue queue = new LinkedList();
queue.add(this.rootNode);
printNode(this.rootNode);
rootNode.visited = true;
while(!queue.isEmpty()) {
Node node = (Node)queue.remove();
Node child=null;
while((child=getUnvisitedChildNode(node))!=null) {
child.visited=true;
printNode(child);
queue.add(child);
}
}
// Clear visited property of nodes
clearNodes();
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment