Class Stack

java.lang.Object
edu.ksu.cis.viewer.Stack
All Implemented Interfaces:
Cloneable

public final class Stack extends Object implements Cloneable
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)
  • Constructor Summary

    Constructors
    Constructor
    Description
    Constructs an empty Stack.
  • Method Summary

    Modifier and Type
    Method
    Description
    Returns a clone of this stack.
    boolean
    Returns true if the stack is empty.
    pop()
    Removes the Object from the top of the stack and returns it.
    void
    push(Object obj)
    Pushes the given Object onto the top of the stack.

    Methods inherited from class java.lang.Object

    equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
  • Constructor Details

    • Stack

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

    • push

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

      public Object pop() throws EmptyStackException
      Removes the Object from the top of the stack and returns it.
      Returns:
      the object at 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 Object clone()
      Returns a clone of this stack. Because the underlying structure is immutable, a shallow clone is performed.
      Overrides:
      clone in class Object