public class LinkedStack { Node top; class Node { E element; Node next; } public void push(E element) { Node newNode = new Node(); newNode.element = element; newNode.next = top; top = newNode; } public E pop() { if (top == null) { return null; } E data = top.element; top = top.next; return data; } public E peek() { if (top == null) { return null; } return top.element; } }