Package algs13
Class StackWithNonStaticNode<T>
java.lang.Object
algs13.StackWithNonStaticNode<T>
- All Implemented Interfaces:
Iterable<T>
The
Stack
class represents a last-in-first-out (LIFO) stack of generic items.
It supports the usual push and pop operations, along with methods
for peeking at the top item, testing if the stack is empty, and iterating through
the items in LIFO order.
All stack operations except iteration are constant time.
For additional documentation, see Section 1.3 of Algorithms, 4th Edition by Robert Sedgewick and Kevin Wayne.
-
Nested Class Summary
Modifier and TypeClassDescriptionprivate class
private class
-
Field Summary
-
Constructor Summary
-
Method Summary
Modifier and TypeMethodDescriptionstatic void
A test client.private static <T> boolean
check
(StackWithNonStaticNode<T> that) boolean
isEmpty()
Is the stack empty?iterator()
Return an iterator to the stack that iterates through the items in LIFO order.static void
static void
peek()
Return the item most recently added to the stack.pop()
Delete and return the item most recently added to the stack.void
Add the item to the stack.int
size()
Return the number of items in the stack.toString()
Return string representation.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
-
Field Details
-
N
-
first
-
-
Constructor Details
-
StackWithNonStaticNode
public StackWithNonStaticNode()Create an empty stack.
-
-
Method Details
-
isEmpty
Is the stack empty? -
size
Return the number of items in the stack. -
push
Add the item to the stack. -
pop
Delete and return the item most recently added to the stack.- Throws:
NoSuchElementException
- if stack is empty.
-
peek
Return the item most recently added to the stack.- Throws:
NoSuchElementException
- if stack is empty.
-
toString
Return string representation. -
check
-
iterator
Return an iterator to the stack that iterates through the items in LIFO order. -
bookMain
A test client. -
main
-
main2
-