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
This interface specifies the API for the stack data structure.
-
Method Summary
Modifier and TypeMethodDescriptionboolean
isEmpty()
Returnstrue
if this stack is empty, andfalse
otherwise.peek()
Returns the item at the top of this stack.pop()
Removes and returns the item at the top of this stack.void
Addsitem
to the top of this stack.int
size()
Returns the number of items in this stack.toString()
Returns a string representation of this stack.Methods inherited from interface java.lang.Iterable
forEach, iterator, spliterator
-
Method Details
-
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
Addsitem
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.
-