java LinkedList类实现队列
/*
LinkedList 类实现队列
队列是FIFO 先进先出FIRST IN FIRST OUT 一边进去另一边出来LinkedList 底层是采用链表完成
ArrayList底层采用数组完成对数据的查找操作用数组更快
*/
import java.util.LinkedList;
class MyQueue
{
private LinkedList ll=new LinkedList();
void put(Object o)
{
ll.addLast(o); //尾部添加元素
}
public Object get()
{
return ll.removeFirst(); //从前面删除
}
public boolean empty()
{
return ll.isEmpty();
}
public static void main(String[] args)
{
MyQueue mq=new MyQueue();
mq.put("one");
mq.put("two");
mq.put("three");
System.out.println(mq.get());
System.out.println(mq.get());
System.out.println(mq.get());
System.out.println(mq.empty());
}