linkedqueue.java
来自「java版的数据结构的完全代码 免费提供了 学习数据结构的请下载」· Java 代码 · 共 42 行
JAVA
42 行
// Introduced in Chapter 6/** A linked Queue. */public class LinkedQueue<E> implements Queue<E> { /** The front ListNode in the Queue. */ private ListNode<E> front; /** The back ListNode in the Queue. */ private ListNode<E> back; /** The Queue is initially empty. */ public LinkedQueue() { front = null; back = null; } public void add(E target) { ListNode<E> node = new ListNode<E>(target); if (isEmpty()) { front = node; back = node; } else { back.setNext(node); back = node; } } public boolean isEmpty() { return front == null; } public E remove() { if (isEmpty()) { throw new EmptyStructureException(); } E result = front.getItem(); front = front.getNext(); return result; } }
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?