Class LinkedQueue<E>

java.lang.Object
com.zybooks.dsaj.stackqueue.LinkedQueue<E>
Type Parameters:
E - the element type
All Implemented Interfaces:
Queue<E>

public class LinkedQueue<E> extends Object implements Queue<E>
Realization of a FIFO queue as an adaptation of a SinglyLinkedList. All operations are performed in constant time.
See Also:
  • Constructor Summary

    Constructors
    Constructor
    Description
    Constructs an initially empty queue.
  • Method Summary

    Modifier and Type
    Method
    Description
    Removes and returns the first element of the queue.
    void
    enqueue(E element)
    Adds an element at the rear of the queue.
    Returns, but does not remove, the first element of the queue.
    boolean
    Tests whether the queue is empty.
    int
    Returns the number of elements in the queue.
    Produces a string representation of the contents of the queue.

    Methods inherited from class java.lang.Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
  • Constructor Details

    • LinkedQueue

      public LinkedQueue()
      Constructs an initially empty queue.
  • Method Details

    • size

      public int size()
      Returns the number of elements in the queue.
      Specified by:
      size in interface Queue<E>
      Returns:
      number of elements in the queue
    • isEmpty

      public boolean isEmpty()
      Tests whether the queue is empty.
      Specified by:
      isEmpty in interface Queue<E>
      Returns:
      true if the queue is empty, false otherwise
    • enqueue

      public void enqueue(E element)
      Adds an element at the rear of the queue.
      Specified by:
      enqueue in interface Queue<E>
      Parameters:
      element - the element to be added
    • first

      public E first()
      Returns, but does not remove, the first element of the queue.
      Specified by:
      first in interface Queue<E>
      Returns:
      the first element of the queue (or null if empty)
    • dequeue

      public E dequeue()
      Removes and returns the first element of the queue.
      Specified by:
      dequeue in interface Queue<E>
      Returns:
      element removed (or null if empty)
    • toString

      public String toString()
      Produces a string representation of the contents of the queue. (from front to back). This exists for debugging purposes only.
      Overrides:
      toString in class Object