public class LinkedStack implements Stack { private static class Elem { private T info; private Elem next; private Elem( T info, Elem next) { this.info = info; this.next = next; } } private Elem top; // instance variable public LinkedStack() { top = null; } public boolean isEmpty() { return top == null; } public void push( E info ) { top = new Elem( info, top ); } public E peek() { return top.info; } public E pop() { E savedInfo = top.info; Elem oldTop = top; Elem newTop = top.next; top = newTop; oldTop.info = null; // scrubbing the memory oldTop.next = null; // scrubbing the memory return savedInfo; } }