Package project2
Class LinkedStack<T>
java.lang.Object
project2.LinkedStack<T>
- Type Parameters:
T
- the type of the elements in the stack
- All Implemented Interfaces:
StackInterface<T>
A class of stacks whose entries are stored in a chain of nodes.
Implements the StackInterface.
- Version:
- 1.0
- Author:
- Lea Wiranatha
-
Constructor Summary
-
Method Summary
-
Constructor Details
-
LinkedStack
public LinkedStack()Creates an empty stack.
-
-
Method Details
-
push
Adds a new entry to the top of this stack.- Specified by:
push
in interfaceStackInterface<T>
- Parameters:
newEntry
- An object to be added to the stack.- Throws:
EmptyStackException
- if the stack is empty
-
pop
Removes and returns this stack's top entry.- Specified by:
pop
in interfaceStackInterface<T>
- Returns:
- The object at the top of the stack.
- Throws:
EmptyStackException
- if the stack is empty
-
peek
Retrieves this stack's top entry.- Specified by:
peek
in interfaceStackInterface<T>
- Returns:
- The object at the top of the stack.
- Throws:
EmptyStackException
- if the stack is empty
-
isEmpty
public boolean isEmpty()Detects whether this stack is empty.- Specified by:
isEmpty
in interfaceStackInterface<T>
- Returns:
- True if the stack is empty.
-
clear
public void clear()Removes all entries from this stack.- Specified by:
clear
in interfaceStackInterface<T>
-