BigIdiot
package com.kk.Collection;

import java.util.LinkedList;
/**
* 模拟一个队列
* 先进先出(FIFO)
*/
public class MyQueue {

public static void main(String[] args) {
MyQueue queue=new MyQueue();
queue.put("a");
queue.put("b");
queue.put("c");
queue.put("d");
System.out.println(queue.get());
System.out.println(queue.get());
System.out.println(queue.get());
System.out.println(queue.get());
System.out.println(queue.empty());
}

private LinkedList list = new LinkedList();

public void put(Object o) {
list.addLast(o); //添加到队列的尾部
}

public Object get() {
return list.removeFirst();//获取队列,因为队列是不能获取某个指定元素,所有只能拿第一个
}

public boolean empty() {
return list.isEmpty();
}
}



分类:

技术点:

相关文章:

  • 2022-12-23
  • 2021-08-04
  • 2021-06-06
  • 2021-11-02
  • 2021-07-05
  • 2021-08-24
  • 2022-01-17
  • 2021-12-08
猜你喜欢
  • 2021-12-22
  • 2022-02-12
  • 2021-10-07
  • 2021-12-12
  • 2022-12-23
  • 2021-06-21
相关资源
相似解决方案