weiss.nonstandard
Class ArrayStack<AnyType>

java.lang.Object
  extended by weiss.nonstandard.ArrayStack<AnyType>
All Implemented Interfaces:
Stack<AnyType>

public class ArrayStack<AnyType>
extends java.lang.Object
implements Stack<AnyType>

Array-based implementation of the stack.


Constructor Summary
ArrayStack()
          Construct the stack.
 
Method Summary
 boolean isEmpty()
          Test if the stack is logically empty.
 void makeEmpty()
          Make the stack logically empty.
 void pop()
          Remove the most recently inserted item from the stack.
 void push(AnyType x)
          Insert a new item into the stack.
 AnyType top()
          Get the most recently inserted item in the stack.
 AnyType topAndPop()
          Return and remove the most recently inserted item from the stack.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

ArrayStack

public ArrayStack()
Construct the stack.

Method Detail

isEmpty

public boolean isEmpty()
Test if the stack is logically empty.

Specified by:
isEmpty in interface Stack<AnyType>
Returns:
true if empty, false otherwise.

makeEmpty

public void makeEmpty()
Make the stack logically empty.

Specified by:
makeEmpty in interface Stack<AnyType>

top

public AnyType top()
Get the most recently inserted item in the stack. Does not alter the stack.

Specified by:
top in interface Stack<AnyType>
Returns:
the most recently inserted item in the stack.
Throws:
UnderflowException - if the stack is empty.

pop

public void pop()
Remove the most recently inserted item from the stack.

Specified by:
pop in interface Stack<AnyType>
Throws:
UnderflowException - if the stack is empty.

topAndPop

public AnyType topAndPop()
Return and remove the most recently inserted item from the stack.

Specified by:
topAndPop in interface Stack<AnyType>
Returns:
the most recently inserted item in the stack.
Throws:
Underflow - if the stack is empty.

push

public void push(AnyType x)
Insert a new item into the stack.

Specified by:
push in interface Stack<AnyType>
Parameters:
x - the item to insert.