package DataStructures; import java.util.NoSuchElementException; /** * A linked list implementation of a stack * @author Peter Williams */ public class StackList implements Stack { private ListNode top; public StackList() { top = null; } public boolean isEmpty() { return top == null; } public void push(Object item) { top = new ListNode(item, top); } public Object pop() { if (top == null) { throw new NoSuchElementException(); } else { Object item = top.data; top = top.next; return item; } } }