import java.util.*; public class IntStack { private Node top; private class Node { private int data; private Node next; private Node(int item) { data = item; next = null; } } public IntStack () { top = null; } public void push(int item) { Node n = new Node(item); n.next = top; top = n; } public int pop() throws EmptyStackException { int v; if ( top == null ) throw new EmptyStackException(); v = top.data; top = top.next; return v; } public int peek() throws EmptyStackException { if ( top == null ) throw new EmptyStackException(); return top.data; } public void dumpStack() { Node p = top; while ( p != null ) { System.out.println(p.data); p = p.next; } } public boolean isEmpty() { return top == null; } }