Interface Stack<Item>

Type Parameters:
Item - the item type
All Superinterfaces:
Container<Item>, 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 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)