Package dsa.lab03.base
Interface Stack<Item>
- Type Parameters:
Item
- the item type
- All Known Implementing Classes:
ArrayStack
,ArrayStack
,LinkedStack
,LinkedStack
A stack.
A LIFO (Last-In, First-Out) structure where items are added (pushed) to and removed (popped) from the top.
-
Method Summary
Methods inherited from interface java.lang.Iterable
forEach, spliterator
-
Method Details
-
push
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)
-