//Implementation of a Stack (Last In First Out List) of Objects import java.util.*; public class Stack { //Instance Variable: Stores the Objects added into this Stack private LinkedList store; //Constructor: Initializes an empty Stack public Stack() { this.store = new LinkedList(); } //Accessor: Answers whether this Stack is empty public boolean isEmpty() { return this.store.isEmpty(); } //Accessor: Returns the Object on the TOP without removing it // Returns null if this Stack is empty public Object peek() { if (this.store.isEmpty()) return null; return this.store.getFirst(); } //Mutator: Adds an Object to the TOP of this Stack public void push(Object item) { this.store.addFirst(item); } //Mutator: Removes and returns the Object from the TOP of this Stack // Throws a "Stack Underflow" Exception if this Stack is empty public Object pop() { if (this.store.isEmpty()) throw new RuntimeException("Stack Underflow"); return this.store.removeFirst(); } }