Interface StackGeneric_Interface<E>

Type Parameters:
E - Type of elements stored in the stack.
All Known Implementing Classes:
DLinked_StackGeneric

public interface StackGeneric_Interface<E>
A generic stack.
Author:
Kevin Lillis
  • Method Summary

    Modifier and Type
    Method
    Description
    void
    Removes all elements from this stack.
    boolean
    Returns true if this stack is empty, returns false otherwise.
    Returns but does not remove the element at the top of this stack.
    pop()
    Removes and returns the element at the top of this stack.
    void
    push(E element)
    Adds the given element to the top of the stack.
    int
    Returns the number of elements in this stack.
    Returns a string containing each element in this list, separated by commas, enclosed in square brackets.
  • Method Details

    • push

      void push(E element)
      Adds the given element to the top of the stack.
      Parameters:
      element - element to be added to the top of this stack
    • pop

      E pop() throws EmptyStackException
      Removes and returns the element at the top of this stack.
      Returns:
      the element at the top of this stack
      Throws:
      EmptyStackException - if this stack is empty.
    • peek

      E peek() throws EmptyStackException
      Returns but does not remove the element at the top of this stack.
      Returns:
      the element at the top of this stack.
      Throws:
      EmptyStackException - if this stack is empty.
    • size

      int size()
      Returns the number of elements in this stack.
      Returns:
      number of elements in this stack
    • isEmpty

      boolean isEmpty()
      Returns true if this stack is empty, returns false otherwise.
      Returns:
      true if this stack is empty, returns false otherwise
    • clear

      void clear()
      Removes all elements from this stack. If the stack is empty, nothing is done.
    • toString

      String toString()
      Returns a string containing each element in this list, separated by commas, enclosed in square brackets. The top of the stack is indicated to the left. For example: TOS [e1, e1, e3]
      Overrides:
      toString in class Object
      Returns:
      a string representation of this list.