public class Demo {
public static void main(String[] args) {
Stack st = new Stack();
st.in("a");
st.in("b");
st.in("c");
st.in("d");
System.out.println(st.out());
System.out.println(st.out());
System.out.println(st.out());
System.out.println(st.out());
}
}
public class Stack {
private LinkedList list = new LinkedList(); //创建LinkedList对象
public void in(Object obj) {
list.addLast(obj); //封装addLast()方法
}
public Object out() {
return list.removeLast(); //封装removeLast()方法
}
public boolean isEmpty() {
return list.isEmpty(); //封装isEmpty()方法
}
} |