Package dsa.lab03.exercises
Class ArrayStack<Item>
java.lang.Object
dsa.lab03.exercises.ArrayStack<Item>
- Type Parameters:
Item
- the item type
An array stack.
Implements the stack interface by using a dynamic array.
-
Constructor Summary
ConstructorDescriptionConstruct an empty array stack.ArrayStack
(Item... items) Construct an array stack containing the given items.ArrayStack
(Iterable<Item> items) Construct an array stack containing the given items.ArrayStack
(Iterable<Item> items, int size) Construct an array stack containing the given items more efficiently thanArrayStack(Iterable)
. -
Method Summary
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
Methods inherited from interface java.lang.Iterable
forEach, spliterator
-
Constructor Details
-
ArrayStack
public ArrayStack()Construct an empty array stack. -
ArrayStack
Construct an array stack containing the given items.- Parameters:
items
- the items
-
ArrayStack
Construct an array stack containing the given items more efficiently thanArrayStack(Iterable)
.- Parameters:
items
- the itemssize
- the number of items- Throws:
IllegalArgumentException
- ifsize
!=n
(wheren
isitems
's size)
-
ArrayStack
Construct an array stack containing the given items.- Parameters:
items
- the items
-
-
Method Details
-
push
Description copied from interface:Stack
Push (insert) the given item onto the top. -
pop
Description copied from interface:Stack
Pop (remove and return) the given item from the top.- Specified by:
pop
in interfaceStack<Item>
- Returns:
- the old top item
- Throws:
NoSuchElementException
- if there's no top item to remove (i.e. if this is empty)
-
top
Description copied from interface:Stack
Get the item on top.- Specified by:
top
in interfaceStack<Item>
- Returns:
- the top item
- Throws:
NoSuchElementException
- if there's no top item to retrieve (i.e. if this is empty)
-
size
public int size()Description copied from interface:Container
Get the number of contained items. -
items
Description copied from interface:Container
Get an iterable that yields each item once.
-