ublic class demo1<T> {
private static class node<U>{
U item;
node<U> next;
node(){
item=null;
next=null;
}
node(U item,node<U> next){
this.item=item;
this.next=next;
}
boolean end(){
return item==null && next==null;
}
}
//建立头部
private node<T> top=new node<T>();
//出栈和入栈的方法
public void push(T item){
top=new node<T>(item,top);
}
public T pop(){
T result=top.item;
if(!top.end()){
top=top.next;
}
return result;
}
public static void main(String[] args) {
System.out.println("????");
demo1<String> stack=new demo1<String>();
for(String str:"a b c d e f".split(" ")){
stack.push(str);
}
String s;
while((s=stack.pop())!=null){
System.out.print(s);
}
}
}
private static class node<U>{
U item;
node<U> next;
node(){
item=null;
next=null;
}
node(U item,node<U> next){
this.item=item;
this.next=next;
}
boolean end(){
return item==null && next==null;
}
}
//建立头部
private node<T> top=new node<T>();
//出栈和入栈的方法
public void push(T item){
top=new node<T>(item,top);
}
public T pop(){
T result=top.item;
if(!top.end()){
top=top.next;
}
return result;
}
public static void main(String[] args) {
System.out.println("????");
demo1<String> stack=new demo1<String>();
for(String str:"a b c d e f".split(" ")){
stack.push(str);
}
String s;
while((s=stack.pop())!=null){
System.out.print(s);
}
}
}