-
-
Save markprovan/4758214 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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