public class Stack { private Node first ; private class Node { private Node next ; private int data ; } public boolean isEmpty() { return (first == null) ; } public void push(int newData) { Node oldfirst = first ; first = new Node() ; first.data = newData ; first.next = oldfirst ; } public int pop() { int returnVal = first.data ; first = first.next ; return returnVal ; } public static void main( String args[]) { Stack s = new Stack() ; s.push(10) ; s.push(5) ; s.push(2) ; while (!s.isEmpty() ) { System.out.println( s.pop() ) ; } } }