package com.fanxing.lining.last;
public class LinkStack <T>{
private class Node<U>{
U item;
Node<U> next;
Node(){
this.item=null;
this.next=null;
}
Node(U item,Node<U> next){
this.item=item;
this.next=next;
}
boolean empty(){
return this.item==null&&this.next==null;
}
}
Node<T> top=new Node<T>();
public void push(T t){
top=new Node<T>(t,top);
}
public T pop(){
T result=top.item;
if(!top.empty())
top=top.next;
return result;
}
public static void main(String[] args) {
LinkStack<String> ls=new LinkStack<String>();
for(int i=0;i<10;i++)
ls.push("str"+i);
String s;
while((s=ls.pop())!=null)
System.out.println(s);
System.out.println(ls.top.empty());
}
}