public class LinkedListBasedStack { private class Node { int value; Node next; } Node head = null; boolean isEmpty () { return (head == null); } void push (int value) { Node newHead = new Node(); newHead.next = head; newHead.value = value; head = newHead; } int pop () { int ret = head.value; head = head.next; return ret; } }