Package dsa

Interface Stack<T>

Type Parameters:
T - the type of items in the stack.
All Superinterfaces:
Iterable<T>
All Known Implementing Classes:
LinkedStack, ResizingArrayStack

public interface Stack<T> extends Iterable<T>
This interface specifies the API for the stack data structure.
  • Method Summary

    Modifier and Type
    Method
    Description
    boolean
    Returns true if this stack is empty, and false otherwise.
    Returns the item at the top of this stack.
    pop()
    Removes and returns the item at the top of this stack.
    void
    push(T item)
    Adds item to the top of this stack.
    int
    Returns the number of items in this stack.
    Returns a string representation of this stack.

    Methods inherited from interface java.lang.Iterable

    forEach, iterator, spliterator
  • Method Details

    • isEmpty

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

      int size()
      Returns the number of items in this stack.
      Returns:
      number of items in this stack.
    • push

      void push(T item)
      Adds item to the top of this stack.
      Parameters:
      item - the item.
    • peek

      T peek()
      Returns the item at the top of this stack.
      Returns:
      item at the top of this stack.
    • pop

      T pop()
      Removes and returns the item at the top of this stack.
      Returns:
      item at the top of this stack.
    • toString

      String toString()
      Returns a string representation of this stack.
      Overrides:
      toString in class Object
      Returns:
      a string representation of this stack.