package ch03.stacks; public interface UnboundedStackInterface extends StackInterface { void push(T element); } ================================================================ package support; public class LLNode { private LLNode link = null; private T info; public LLNode(T info) { this.info = info; } public void setInfo(T info) { this.info = info; } public T getInfo() { return info; } public void setLink(LLNode link) { this.link = link; } public LLNode getLink() { return link; } } ================================================================ package ch03.stacks; import support.LLNode; public class LinkedStack implements UnboundedStackInterface { protected LLNode top; // reference to the top of this stack public LinkedStack() { top = null; } public void push(T element) { LLNode newNode = new LLNode(element); newNode.setLink(top); top = newNode; } public void pop() { // Throws StackUnderflowException if this stack is empty, // otherwise removes top element from this stack. if (isEmpty()) throw new StackUnderflowException("Helpful msg."); top = top.getLink(); } public T top() { // Throws StackUnderflowException if this stack is empty, // otherwise returns top element from this stack. if (isEmpty()) throw new StackUnderflowException("Helpful msg."); return top.getInfo(); } public boolean isEmpty() { return top == null; } }