public class LinkedStack implements Stack { private static class Elem { private T value; private Elem next; private Elem(T value, Elem next) { this.value = value; this.next = next; } } private Elem top; public boolean isEmpty() { return top == null; } public void push(E value) { top = new Elem(value, top); } public E peek() { return top.value; } public E pop() { E saved = top.value; top = top.next; return saved; } }