Class SearchAlgorithm
java.lang.Object
|
+----SearchAlgorithm
- public class SearchAlgorithm
- extends Object
A generic search algorithm, implementing the basic methods needed
for a search. The three main methods that need to be overridden in
order to make a specific search algorithm are search(), searchQueue(),
and enqueue().
- Author:
- Naomi Novik
-
depth
- Maximum depth in the tree to search until, used in depth-limited
and iterative-deepening search algorithms.
-
nodeQueue
- Vector containing the queue of nodes to search.
-
searchString
- What to look for.
-
stopRequested
- When true stop searching.
-
SearchAlgorithm()
- Constructor.
-
clearSearch()
- Clear the search.
-
enqueue(WNode)
- This method will be called to enqueue a new node.
-
init()
- Initialize
-
pause()
- Pause for a while.
-
peek()
- Peek at the top value of nodeQueue.
-
pop()
- Pop off the top value of nodeQueue.
-
search(WNode, String)
- This method will be called to search through a tree.
-
searchQueue()
- Recursively called to search through the queue of nodes.
-
setCaller(SearchApplet)
- Set the caller.
-
setDepth(int)
- Set depth.
-
stop()
- Stop searching.
stopRequested
protected boolean stopRequested
- When true stop searching.
nodeQueue
protected Vector nodeQueue
- Vector containing the queue of nodes to search.
searchString
protected String searchString
- What to look for.
depth
protected int depth
- Maximum depth in the tree to search until, used in depth-limited
and iterative-deepening search algorithms.
SearchAlgorithm
public SearchAlgorithm()
- Constructor.
setCaller
public void setCaller(SearchApplet c)
- Set the caller.
setDepth
public void setDepth(int d)
- Set depth.
clearSearch
protected void clearSearch()
- Clear the search.
stop
public void stop()
- Stop searching.
init
public void init()
- Initialize
pop
protected WNode pop()
- Pop off the top value of nodeQueue.
peek
protected WNode peek()
- Peek at the top value of nodeQueue.
pause
protected void pause() throws Exception
- Pause for a while.
search
public WNode search(WNode root,
String searchString) throws Exception
- This method will be called to search through a tree.
searchQueue
protected WNode searchQueue() throws Exception
- Recursively called to search through the queue of nodes.
Return the node if searchString found.
enqueue
protected void enqueue(WNode newNode)
- This method will be called to enqueue a new node.
Should be overridden by child classes.