public class LinkedListStack<T> {
Node<T> top=new Node<T>();
private static class Node<U> {
U e;
Node<U> next;
public Node(){this.e=null;this.next=null;}
public Node(U e,Node<U> next){ this.e=e;this.next=next;}
public boolean end(){return e==null && next==null;}
}
public void push(T e){
top=new Node<T>(e,top);
}
public T pop(){
T result=top.e;
if(!top.end())
top=top.next;
return result;
}
public static void main(String[] args){
LinkedListStack<Integer> ss=new LinkedListStack<Integer>();
for(int i=1;i<5;i++)
ss.push(i);
Integer i;
while((i=ss.pop())!=null)
System.out.println(i);
}
}