Package com.zybooks.dsaj.stackqueue
Class LinkedStack<E>
java.lang.Object
com.zybooks.dsaj.stackqueue.LinkedStack<E>
- Type Parameters:
E
- the element type
- All Implemented Interfaces:
Stack<E>
Realization of a stack as an adaptation of a SinglyLinkedList.
All operations are performed in constant time.
- See Also:
-
Constructor Summary
-
Method Summary
Modifier and TypeMethodDescriptionboolean
isEmpty()
Tests whether the stack is empty.pop()
Removes and returns the top element from the stack.void
Adds an element at the top of the stack.int
size()
Returns the number of elements in the stack.top()
Returns, but does not remove, the element at the top of the stack.toString()
Produces a string representation of the contents of the stack.
-
Constructor Details
-
LinkedStack
public LinkedStack()Constructs an initially empty stack.
-
-
Method Details
-
size
public int size()Returns the number of elements in the stack. -
isEmpty
public boolean isEmpty()Tests whether the stack is empty. -
push
Adds an element at the top of the stack. -
top
Returns, but does not remove, the element at the top of the stack. -
pop
Removes and returns the top element from the stack. -
toString
Produces a string representation of the contents of the stack. (ordered from top to bottom) This exists for debugging purposes only.
-