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

Variable Index

 o depth
Maximum depth in the tree to search until, used in depth-limited and iterative-deepening search algorithms.
 o nodeQueue
Vector containing the queue of nodes to search.
 o searchString
What to look for.
 o stopRequested
When true stop searching.

Constructor Index

 o SearchAlgorithm()
Constructor.

Method Index

 o clearSearch()
Clear the search.
 o enqueue(WNode)
This method will be called to enqueue a new node.
 o init()
Initialize
 o pause()
Pause for a while.
 o peek()
Peek at the top value of nodeQueue.
 o pop()
Pop off the top value of nodeQueue.
 o search(WNode, String)
This method will be called to search through a tree.
 o searchQueue()
Recursively called to search through the queue of nodes.
 o setCaller(SearchApplet)
Set the caller.
 o setDepth(int)
Set depth.
 o stop()
Stop searching.

Variables

 o stopRequested
 protected boolean stopRequested
When true stop searching.

 o nodeQueue
 protected Vector nodeQueue
Vector containing the queue of nodes to search.

 o searchString
 protected String searchString
What to look for.

 o depth
 protected int depth
Maximum depth in the tree to search until, used in depth-limited and iterative-deepening search algorithms.

Constructors

 o SearchAlgorithm
 public SearchAlgorithm()
Constructor.

Methods

 o setCaller
 public void setCaller(SearchApplet c)
Set the caller.

 o setDepth
 public void setDepth(int d)
Set depth.

 o clearSearch
 protected void clearSearch()
Clear the search.

 o stop
 public void stop()
Stop searching.

 o init
 public void init()
Initialize

 o pop
 protected WNode pop()
Pop off the top value of nodeQueue.

 o peek
 protected WNode peek()
Peek at the top value of nodeQueue.

 o pause
 protected void pause() throws Exception
Pause for a while.

 o search
 public WNode search(WNode root,
                     String searchString) throws Exception
This method will be called to search through a tree.

 o searchQueue
 protected WNode searchQueue() throws Exception
Recursively called to search through the queue of nodes. Return the node if searchString found.

 o enqueue
 protected void enqueue(WNode newNode)
This method will be called to enqueue a new node. Should be overridden by child classes.