PHP Code: // Breadth First Search Usage in the common Eight Puzzle Problem. import java.util.*; class EightPuzzle { Queue q = new LinkedList(); // Use of Queue Implemented using LinkedList for Storing All the Nodes in BFS. Map map = new HashMap(); // HashMap is used to ignore repeated nodes public static void main(String args[]){ String str="087465132"; // Input the ...
Using a queue sounds like the right implementation, first in first out. So starting from your headnode, add left, right node if not null, to the queue and print the headnode. While queue is not empty, look at first item, add left, right node if not null to end of queue and print the current node. Remove next item from queue ...