Algorithm
Development Kit 1.0

algs.model.searchtree.states
Class StateStack

java.lang.Object
  extended by algs.model.searchtree.states.StateStack
All Implemented Interfaces:
INodeSet

public class StateStack
extends java.lang.Object
implements INodeSet

Provide storage that behaves like a stack. INodeSet.insert(INode) and INodeSet.remove() are constant time operations. However, INodeSet.contains(INode) becomes O(n) since the entire stack must be inspected. Finally, INodeSet.remove(INode) is O(n) since whole stack must be searched.

Since:
1.0
Version:
1.0, 6/15/08
Author:
George Heineman

Constructor Summary
StateStack()
           
 
Method Summary
 INode contains(INode n)
          A costly operation in a stack; typically not required.
 void insert(INode n)
          Insert pushes the element onto the stack.
 boolean isEmpty()
          Is stack empty?
 java.util.Iterator<INode> iterator()
          Expose iterator to internal board states.
 INode remove()
          Remove takes the topmost element from the stack.
 boolean remove(INode n)
          Remove actual value from the list.
 int size()
          Determine number of states in the set.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

StateStack

public StateStack()
Method Detail

insert

public void insert(INode n)
Insert pushes the element onto the stack.

Specified by:
insert in interface INodeSet
Parameters:
n - the INode to store in the set.

remove

public INode remove()
Remove takes the topmost element from the stack.

Specified by:
remove in interface INodeSet

isEmpty

public boolean isEmpty()
Is stack empty?

Specified by:
isEmpty in interface INodeSet

size

public int size()
Determine number of states in the set.

Specified by:
size in interface INodeSet

iterator

public java.util.Iterator<INode> iterator()
Expose iterator to internal board states.

Specified by:
iterator in interface INodeSet

contains

public INode contains(INode n)
A costly operation in a stack; typically not required.

Specified by:
contains in interface INodeSet
Parameters:
n - the target node to be looked for.

remove

public boolean remove(INode n)
Remove actual value from the list.

Specified by:
remove in interface INodeSet
Parameters:
n - the node representing the value to be removed from the set.
See Also:
INodeSet.remove(INode)

Algorithm Development Kit 1.0

This code supports the Algorithms in a Nutshell book, published by O'Reilly Media, Inc. in November 2008. Please visit the book web page to learn of any changes to the code repository or to record a potential defect.