The LinkedStack Class
Here is the class, with its node, fields, and constructor:
public class LinkedStack<T> implements Stack<T> {
private Node<T> head; // the top of the stack, or null when empty
private static class Node<T> {
T value;
Node<T> next;
Node(T value) {
this.value = value;
}
}
public LinkedStack() {
head = null; // the stack starts empty
}
@Override
public boolean isEmpty() {
return head == null;
}
// ... the operations will go here
}
Notice I also implemented isEmpty here.