Class GenericStack<E extends Serializable>

java.lang.Object
edu.ksu.cis.viewer.GenericStack<E>
Type Parameters:
E - the type of the elements in the stack
All Implemented Interfaces:
Serializable

public final class GenericStack<E extends Serializable> extends Object implements Serializable
A stack built from an immutable ConsList. Using an immutable structure for the underlying storage allows a shallow clone to be sufficient.
Author:
Rod Howell (rhowell@ksu.edu)
See Also:
  • Constructor Details

    • GenericStack

      public GenericStack()
      Constructs an empty Stack.
  • Method Details

    • push

      public void push(E obj)
      Pushes the given Object onto the top of the stack.
      Parameters:
      obj - the object to push onto the stack
    • pop

      public E pop() throws EmptyStackException
      Removes the element from the top of the stack and returns it.
      Returns:
      the element removed from the top of the stack
      Throws:
      EmptyStackException - If the stack is empty.
    • empty

      public boolean empty()
      Returns true if the stack is empty.
      Returns:
      whether this stack is empty
    • clone

      public GenericStack<E> clone()
      Returns a clone of this stack. Because the underlying structure is immutable, a shallow clone is performed.
      Overrides:
      clone in class Object