LinkedList 模拟队列的结构

package facetest;
public class FaceTest1 {

public FaceTest1() {
// TODO Auto-generated constructor stub
}
/*
*请使用linkedlist来模拟一个堆栈或一个队列结构
*
*思路: 堆栈 先进后出 First in  end out    FIEO
* 队列 先进先出 First in First out   FIFO 
* */
public static void main(String[] args) {
Troops tr = new Troops();
tr.myAdd( " haha " );
tr.myAdd("bb");

while ( ! tr.isNull () ) {

System.out.println(tr.myGet());

}

}

}

package facetest;


import java.util.Iterator;
import java.util.LinkedList;

public class Troops {


private LinkedList link;
public Troops() {
link = new LinkedList();
}
public void myAdd (Object obj){
link.addLast(obj);
}
public  Object myGet (){

return link.removeFirst();
}
public boolean isNull (){

return link.isEmpty();

}
}

你可能感兴趣的:(collection)