Package dsa
Class ResizingArrayStack<T>
java.lang.Object
dsa.ResizingArrayStack<T>
- Type Parameters:
T
- the type of items in the stack.
This data type provides an implementation of the Stack API, using an array as the underlying data structure.
-
Constructor Summary
-
Method Summary
Modifier and TypeMethodDescriptionboolean
isEmpty()
Returnstrue
if this stack is empty, andfalse
otherwise.iterator()
Returns an iterator to iterate over the items in this stack in LIFO order.static void
Unit tests the data type.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 class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
Methods inherited from interface java.lang.Iterable
forEach, spliterator
-
Constructor Details
-
ResizingArrayStack
public ResizingArrayStack()Constructs an empty stack.
-
-
Method Details
-
isEmpty
public boolean isEmpty()Returnstrue
if this stack is empty, andfalse
otherwise. -
size
public int size()Returns the number of items in this stack. -
push
Addsitem
to the top of this stack. -
peek
Returns the item at the top of this stack. -
pop
Removes and returns the item at the top of this stack. -
toString
Returns a string representation of this stack. -
iterator
Returns an iterator to iterate over the items in this stack in LIFO order. -
main
Unit tests the data type.- Parameters:
args
- the command-line arguments.
-