堆栈:先进后出First in Last Out FILO 如同一个杯子
队列:先进先出 First in First out FIFO 如同一个水管
class Duilie{
private LinkedList link;
Duilie(){
link = new LinkedList();
}
public void myAdd(Object obj){
link.addFirst(obj);
}
public Object myGet(){
return link.removeLast();//改为removeLast这样就可以是堆栈和队列的转换
}
public boolean isNull(){
return link.isEmpty();
}
}
public class LinkedListTest {
public static void main(String[] args) {
Duilie dl = new Duilie();
dl.myAdd("java01");
dl.myAdd("java02");
dl.myAdd("java03");
dl.myAdd("java04");
while (!dl.isNull()){
System.out.println(dl.myGet());
}
}
}