类 LinkedQueue<Item>

  • 所有已实现的接口:
    java.lang.Iterable<Item>

    public class LinkedQueue<Item>
    extends java.lang.Object
    implements java.lang.Iterable<Item>
    The LinkedQueue class represents a first-in-first-out (FIFO) queue of generic items. It supports the usual enqueue and dequeue operations, along with methods for peeking at the first item, testing if the queue is empty, and iterating through the items in FIFO order.

    This implementation uses a singly linked list with a non-static nested class for linked-list nodes. See Queue for a version that uses a static nested class. The enqueue, dequeue, peek, size, and is-empty operations all take constant time in the worst case.

    For additional documentation, see Section 1.3 of Algorithms, 4th Edition by Robert Sedgewick and Kevin Wayne.

    • 构造器概要

      构造器 
      构造器 说明
      LinkedQueue()
      Initializes an empty queue.
    • 方法概要

      修饰符和类型 方法 说明
      Item dequeue()
      Removes and returns the item on this queue that was least recently added.
      void enqueue​(Item item)
      Adds the item to this queue.
      boolean isEmpty()
      Is this queue empty?
      java.util.Iterator<Item> iterator()
      Returns an iterator that iterates over the items in this queue in FIFO order.
      static void main​(java.lang.String[] args)
      Unit tests the LinkedQueue data type.
      Item peek()
      Returns the item least recently added to this queue.
      int size()
      Returns the number of items in this queue.
      java.lang.String toString()
      Returns a string representation of this queue.
      • 从类继承的方法 java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
      • 从接口继承的方法 java.lang.Iterable

        forEach, spliterator
    • 构造器详细资料

      • LinkedQueue

        public LinkedQueue()
        Initializes an empty queue.
    • 方法详细资料

      • isEmpty

        public boolean isEmpty()
        Is this queue empty?
        返回:
        true if this queue is empty; false otherwise
      • size

        public int size()
        Returns the number of items in this queue.
        返回:
        the number of items in this queue
      • peek

        public Item peek()
        Returns the item least recently added to this queue.
        返回:
        the item least recently added to this queue
        抛出:
        java.util.NoSuchElementException - if this queue is empty
      • enqueue

        public void enqueue​(Item item)
        Adds the item to this queue.
        参数:
        item - the item to add
      • dequeue

        public Item dequeue()
        Removes and returns the item on this queue that was least recently added.
        返回:
        the item on this queue that was least recently added
        抛出:
        java.util.NoSuchElementException - if this queue is empty
      • toString

        public java.lang.String toString()
        Returns a string representation of this queue.
        覆盖:
        toString 在类中 java.lang.Object
        返回:
        the sequence of items in FIFO order, separated by spaces
      • iterator

        public java.util.Iterator<Item> iterator()
        Returns an iterator that iterates over the items in this queue in FIFO order.
        指定者:
        iterator 在接口中 java.lang.Iterable<Item>
        返回:
        an iterator that iterates over the items in this queue in FIFO order
      • main

        public static void main​(java.lang.String[] args)
        Unit tests the LinkedQueue data type.
        参数:
        args - the command-line arguments