Package dsa

Class LinkedQueue<T>

java.lang.Object
dsa.LinkedQueue<T>
Type Parameters:
T - the type of items in the queue.
All Implemented Interfaces:
Queue<T>, Iterable<T>

public class LinkedQueue<T> extends Object implements Queue<T>
This data type provides an implementation of the Queue API, using a linked-list as the underlying data structure.
  • Constructor Summary

    Constructors
    Constructor
    Description
    Constructs an empty queue.
  • Method Summary

    Modifier and Type
    Method
    Description
    Removes and returns the item at the front of this queue.
    void
    enqueue(T item)
    Adds item to the end of this queue.
    boolean
    Returns true if this queue is empty, and false otherwise.
    Returns an iterator to iterate over the items in this queue in FIFO order.
    static void
    main(String[] args)
    Unit tests the data type.
    Returns the item at the front of this queue.
    int
    Returns the number of items in this queue.
    Returns a string representation of this queue.

    Methods inherited from class java.lang.Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait

    Methods inherited from interface java.lang.Iterable

    forEach, spliterator
  • Constructor Details

    • LinkedQueue

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

    • isEmpty

      public boolean isEmpty()
      Returns true if this queue is empty, and false otherwise.
      Specified by:
      isEmpty in interface Queue<T>
      Returns:
      true if this queue is empty, and false otherwise.
    • size

      public int size()
      Returns the number of items in this queue.
      Specified by:
      size in interface Queue<T>
      Returns:
      number of items in this queue.
    • enqueue

      public void enqueue(T item)
      Adds item to the end of this queue.
      Specified by:
      enqueue in interface Queue<T>
      Parameters:
      item - the item.
    • peek

      public T peek()
      Returns the item at the front of this queue.
      Specified by:
      peek in interface Queue<T>
      Returns:
      item at the front of this queue.
    • dequeue

      public T dequeue()
      Removes and returns the item at the front of this queue.
      Specified by:
      dequeue in interface Queue<T>
      Returns:
      item at the front of this queue.
    • toString

      public String toString()
      Returns a string representation of this queue.
      Specified by:
      toString in interface Queue<T>
      Overrides:
      toString in class Object
      Returns:
      a string representation of this queue.
    • iterator

      public Iterator<T> iterator()
      Returns an iterator to iterate over the items in this queue in FIFO order.
      Specified by:
      iterator in interface Iterable<T>
      Returns:
      an iterator to iterate over the items in this queue in FIFO order.
    • main

      public static void main(String[] args)
      Unit tests the data type.
      Parameters:
      args - the command-line arguments.