search
public boolean search(SearchNode rootNode)
search
- given an initial node, perform
depth-first search (DFS). This particular implementation of
DFS is iterative.
The nodeCount is reset at search initialization.
A Stack of SearchNode objects is created and is initialized to
contain only the given rootNode.
The following steps are next iterated:
If the stack is empty, search has failed and we return false.
Otherwise, we pop the stack, increment the node count,
and check if that popped node is a goal node.
If we have found a goal node, set the Searcher goalNode to this node
and return true.
Otherwise, expand the node and push its children onto the stack.
- Specified by:
search
in class Searcher
- Parameters:
rootNode
- a SearchNode
value - the initial node
- Returns:
- a
boolean
value - whether or not goal node
was found