Interface Stack<Item>

Type Parameters:
Item - the item type
All Superinterfaces:
Container<Item>, dsa.lib.DSAInterface, Iterable<Item>
All Known Implementing Classes:
ArrayStack, ArrayStack, LinkedStack, LinkedStack

public interface Stack<Item> extends Container<Item>
A stack.

A LIFO (Last-In, First-Out) structure where items are added (pushed) to and removed (popped) from the top.

  • Method Summary

    Modifier and Type
    Method
    Description
    pop()
    Pop (remove and return) the given item from the top.
    void
    push(Item item)
    Push (insert) the given item onto the top.
    top()
    Get the item on top.

    Methods inherited from interface dsa.lab02.base.Container

    contains, isEmpty, items, iterator, size, toString

    Methods inherited from interface dsa.lib.DSAInterface

    toDebugString

    Methods inherited from interface java.lang.Iterable

    forEach, spliterator
  • Method Details

    • push

      void push(Item item)
      Push (insert) the given item onto the top.
      Parameters:
      item - the new top item
    • pop

      Pop (remove and return) the given item from the top.
      Returns:
      the old top item
      Throws:
      NoSuchElementException - if there's no top item to remove (i.e. if this is empty)
    • top

      Get the item on top.
      Returns:
      the top item
      Throws:
      NoSuchElementException - if there's no top item to retrieve (i.e. if this is empty)