Package dsa
Interface Stack<Item>
-
- All Superinterfaces:
Iterable<Item>
- All Known Implementing Classes:
LinkedStack
,ResizingArrayStack
public interface Stack<Item> extends Iterable<Item>
This interface specifies the API for the stack data structure.
-
-
Method Summary
All Methods Instance Methods Abstract Methods Modifier and Type Method Description boolean
isEmpty()
Returnstrue
if this stack is empty, andfalse
otherwise.Item
peek()
Returns the item at the top of this stack.Item
pop()
Removes and returns the item at the top of this stack.void
push(Item item)
Addsitem
to the top of this stack.int
size()
Returns the number of items in this stack.-
Methods inherited from interface java.lang.Iterable
forEach, iterator, spliterator
-
-
-
-
Method Detail
-
isEmpty
boolean isEmpty()
Returnstrue
if this stack is empty, andfalse
otherwise.- Returns:
true
if this stack is empty, andfalse
otherwise.
-
size
int size()
Returns the number of items in this stack.- Returns:
- number of items in this stack.
-
push
void push(Item item)
Addsitem
to the top of this stack.- Parameters:
item
- the item.
-
peek
Item peek()
Returns the item at the top of this stack.- Returns:
- item at the top of this stack.
-
pop
Item pop()
Removes and returns the item at the top of this stack.- Returns:
- item at the top of this stack.
-
-