Class AStack

java.lang.Object
  |
  +--AStack

public class AStack
extends Object

AStack.java
Illustrates the implementation of a stack based on an ArrayList.

Created: Mon Mar 24 11:26:05 2003

Author:
Stuart C. Shapiro

Constructor Summary
AStack()
          Creates a new AStack instance.
AStack(int initialCapacity)
          Creates a new AStack instance with the given initial capacity.
 
Method Summary
 boolean empty()
          Determines if this AStack is empty.
 Object pop()
          Removes and returns the Object on the top of this AStack.
 void push(Object obj)
          Adds a new Object to the top of this AStack.
 Object top()
          Returns the Object on the top of this AStack.
 String toString()
          Returns a String representation of this AStack, with the top Object shown at the left.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Constructor Detail

AStack

public AStack()
Creates a new AStack instance.


AStack

public AStack(int initialCapacity)
Creates a new AStack instance with the given initial capacity.

Parameters:
initialCapacity - the initial capacity of this AStack.
Method Detail

empty

public boolean empty()
Determines if this AStack is empty.

Returns:
true if this AStack has no elements in it; otherwise returns false.

push

public void push(Object obj)
Adds a new Object to the top of this AStack.

Parameters:
obj - the Object to be pushed onto this AStack.

top

public Object top()
           throws NoSuchElementException
Returns the Object on the top of this AStack.

Returns:
the Object on the top of this AStack.
Throws:
NoSuchElementException - if this AStack is empty.

pop

public Object pop()
           throws NoSuchElementException
Removes and returns the Object on the top of this AStack.

Returns:
the Object that was on the top of this AStack, after removing it.
Throws:
NoSuchElementException - if this AStack is empty.

toString

public String toString()
Returns a String representation of this AStack, with the top Object shown at the left.

Overrides:
toString in class Object
Returns:
a String representation of this AStack.