Package dsa.lab03.solutions
Class LinkedStack<Item>
java.lang.Object
dsa.lib.DSAObject
dsa.lab03.solutions.LinkedStack<Item>
- Type Parameters:
Item- the item type
A linked stack.
Implements the stack interface by using a singly-linked list.
-
Constructor Summary
ConstructorsConstructorDescriptionConstruct an empty linked stack.LinkedStack(Item... items) Construct a linked stack containing the given items.LinkedStack(Iterable<Item> items) Construct a linked stack containing the given items. -
Method Summary
Methods inherited from class dsa.lib.DSAObject
toDebugString, toStringMethods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, waitMethods inherited from interface dsa.lib.DSAInterface
toDebugStringMethods inherited from interface java.lang.Iterable
forEach, spliterator
-
Constructor Details
-
LinkedStack
public LinkedStack()Construct an empty linked stack. -
LinkedStack
Construct a linked stack containing the given items.- Parameters:
items- the items
-
LinkedStack
Construct a linked stack containing the given items.- Parameters:
items- the items
-
-
Method Details
-
push
Description copied from interface:StackPush (insert) the given item onto the top. -
pop
Description copied from interface:StackPop (remove and return) the given item from the top.- Specified by:
popin 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:StackGet the item on top.- Specified by:
topin 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:ContainerGet the number of contained items. -
items
Description copied from interface:ContainerGet an iterable that yields each item once.
-