computer
Class Stack<T>

java.lang.Object
  extended by computer.Stack<T>
Type Parameters:
T - the type of element stored

public class Stack<T>
extends java.lang.Object

A LIFO storage structure. Useful in such things as language translation and in execution of arithmetic expressions. Insertions are only at the "top". Removals are only at the "top".

Author:
jbergin

Field Summary
private  apcsGeneric.jbergin.DenseList<T> storage
           
 
Constructor Summary
Stack()
           
 
Method Summary
 boolean isEmpty()
          Tells if the structure is empty.
 T pop()
          Remove and return the item most recently pushed that has not yet been popped
 void push(T element)
          Enter an item into the storage at the top.
 T top()
          Get a reference to the top of the stack without removing it.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

storage

private apcsGeneric.jbergin.DenseList<T> storage
Constructor Detail

Stack

public Stack()
Method Detail

push

public void push(T element)
Enter an item into the storage at the top.

Parameters:
element - the item to be inserted

pop

public T pop()
Remove and return the item most recently pushed that has not yet been popped

Returns:
the top of the stack
Throws:
java.lang.IllegalStateException - if the stack is empty

top

public T top()
Get a reference to the top of the stack without removing it.

Returns:
the item at the top of the stack
Throws:
java.lang.IllegalStateException - if the stack is empty

isEmpty

public boolean isEmpty()
Tells if the structure is empty.

Returns:
whether or not the stack is empty (has no elements)