[java] view plaincopyprint?01.01.---------------------- <a href="http://www.itheima.com"target="blank">ASP.Net+Unity开发</a>、<a href="http://www.itheima.com"target="blank">.Net培训</a>、期待与您交流! ---------------------- package heimaLog;
import java.util.*;
/*
* 使用LikedList模拟一个堆栈或者队列数据结构
*
* 堆栈:先进后出
* 队列:先进先出
*
*
* */
class DuiLie{
private LinkedList link;
DuiLie(){ link = new LinkedList(); }
public void myadd(Object obj){
link.addFirst(obj);
}
public Object mydGet(){
return link.removeFirst();
}
public Object myfGet(){
return link.removeLast();
}
public boolean isNull(){
return link.isEmpty();
}
}
public class LinkedListTest {
public static void main(String[] args) {
// TODO Auto-generated method stub
DuiLie dl = new DuiLie();
dl.myadd("string 11");
dl.myadd("string 12");
dl.myadd("string 13");
dl.myadd("string 14");
while(!dl.isNull()){
sop(dl.mydGet());
}
}
public static void sop(Object obj){
System.out.println(obj);
}
}
.---------------------- <a href="http://www.itheima.com"target="blank">ASP.Net+Unity开发</a>、<a href="http://www.itheima.com"target="blank">.Net培训</a>、期待与您交流! ----------------------