Skip to content

Instantly share code, notes, and snippets.

@markprovan
Created February 11, 2013 22:27
Show Gist options
  • Select an option

  • Save markprovan/4758214 to your computer and use it in GitHub Desktop.

Select an option

Save markprovan/4758214 to your computer and use it in GitHub Desktop.
public boolean breadthFirstSearch(String s) {
String currentNode;
ArrayList<String> queue = new ArrayList<String>();
queue.add("MI");
Boolean found = false;
int iterations = 0;
while (found == false) {
// Update iteration count
iterations++;
// set current node to next item in agenda
currentNode = queue.remove(0);
if (currentNode == s) {
found = true;
System.out.println(s + " was found after " + iterations + " iterations. Agenda size: " + queue.size());
} else {
Set<String> nexts = nextStates(currentNode);
// Add next states to agenda
for (String set : nexts) {
queue.add(set);
}
}
System.out.println(queue.size());
}
return found;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment