Package cpsc331.collections
Class ListStack<E>
- java.lang.Object
-
- cpsc331.collections.ListStack<E>
-
-
Constructor Summary
Constructors Constructor Description ListStack()
Creates a linked list representing an empty stack.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description boolean
isEmpty()
Reports whether the stack is currently empty without changing it.E
peek()
Reports the top element of the stack without changing it.E
pop()
Removes an element from the top of the stack and reports it.void
push(E x)
Pushes a new entry onto the stack.
-
-
-
Method Detail
-
push
public void push(E x)
Description copied from interface:Stack
Pushes a new entry onto the stack.- Specified by:
push
in interfaceStack<E>
- Parameters:
x
- the object to be pushed onto the stack
Precondition:
- The Stack Invariant is satisfied.
- An element x of type E has been given as input.
- The Stack Invariant is satisfied.
- The input object x has been pushed onto the top of the stack (which is otherwise unchanged).
-
peek
public E peek()
Description copied from interface:Stack
Reports the top element of the stack without changing it.
-
pop
public E pop()
Description copied from interface:Stack
Removes an element from the top of the stack and reports it.
-
isEmpty
public boolean isEmpty()
Description copied from interface:Stack
Reports whether the stack is currently empty without changing it.- Specified by:
isEmpty
in interfaceStack<E>
- Returns:
- true if the stack is empty, and false otherwise
Precondition:
- The Stack Invariant is satisfied.
- The Stack Invariant is satisfied.
- The stack is not changed.
- If the stack was empty before this operation then “true” is returned as output.
- If the stack was not empty before this operation then “false” is returned as output.
-
-