public interface Stack{
public void push(Object obj);
public void pop();
public Object top();
}
public class LinkedStack implements Stack{
private class Node{
private Object item;
private Node next;
private Node(Object item,Node next){
this.item=item;
this.next=next;
}
}
private Node top=null;
private int numberElement=0;
public void push(Object item){
Node newNode = new Node(item, top);
top=newNode;
numberElement++;
}
public void pop(){
}
/*
public void makeEmpty(){
}
*/
public Object top(){
return top.item;
}
public boolean isEmpty(){
return top==null;
}
public int size(){
return numberElement;
}
public static void main(String[] args){
LinkedStack myst=new LinkedStack();
myst.push(new Integer(1));
myst.push(new String("xiabing"));
myst.push(new Short((short)2));
myst.push(new String("Hello!"));
System.out.println(myst.size());
myst.pop();
System.out.println(myst.size());
}
}