标签:oid linked pre 实现 boolean next 数组 链式队列 tmp
前面讲过用数组实现队列,这次看下用链表实现队列。
如有不对请提出,共同提高,谢谢!!
public class LinkedQueue<E> { private Node<E> head = null; /** * 入队 * * @param e * @return */ public boolean enqueue(E e) { Node<E> node = new Node<>(e); if (head == null) { head = node; } else { Node tmpNode = this.head; while (tmpNode.nextNode != null) { tmpNode = tmpNode.nextNode; } tmpNode.nextNode = node; } return true; } /** * 出队 * * @return */ public E dequeue() { if(head == null) { return null; } Node<E> node = head; head = node.nextNode; return node.getT(); } private class Node<T> { private T t; private Node nextNode; public Node(T t) { this.t = t; } public T getT() { return t; } public void setT(T t) { this.t = t; } } }
标签:oid linked pre 实现 boolean next 数组 链式队列 tmp
原文地址:https://www.cnblogs.com/shenqiaqia/p/10482530.html