package it.Collectionfenzhi;
import java.util.LinkedList;
public class MyStack {
private LinkedList link;
public MyStack(){
link = new LinkedList();
}
public void add(Object obj){
link.addFirst(obj);
}
public Object getfirst(){
return link.poll();
}
public int size(){
return link.size();
}
}
package it.Collectionfenzhi;
import java.util.ArrayList;
public class StackTest {
public static void main(String[] args) {
MyStack ms=new MyStack();
ms.add("hello");
ms.add("world");
ms.add("java");
ms.add("qq");
for (int i = ms.size()-1; i >=0; i--) {
System.out.println(ms.getfirst());
}
}
}
|
|