public class LinkedStack<E> implements Stack<E> {
    private ListNode<E> top = null;	// top of the stack
    public boolean isEmpty() {  return this.top == null;  }
    public E peek() {
        if (this.isEmpty()) {  throw new RuntimeException("es");  }
        return this.top.getElem();
    }
    public E pop() {
        E result = this.peek();
        this.top = this.top.getNext();
        return result;
    }
    public void push(E elem) {
        this.top = new ListNode<E>(elem, this.top);
    }
    public static void main(String[] args) {
        Stack<Integer> stack = new LinkedStack<Integer>();
        for (int i = 0; i < 100; i++) {
            stack.push(i*i);
        }
        while (!stack.isEmpty()) {
            System.out.println(stack.pop());
        }
    }
}

