Class LinkedQueue<Item>

java.lang.Object
dsa.lab03.exercises.LinkedQueue<Item>
Type Parameters:
Item - the item type
All Implemented Interfaces:
Container<Item>, Queue<Item>, Iterable<Item>

public class LinkedQueue<Item> extends Object implements Queue<Item>
A linked queue.

Implements the queue interface by using a singly-linked list.

  • Constructor Details

    • LinkedQueue

      public LinkedQueue()
      Construct an empty linked queue.
    • LinkedQueue

      public LinkedQueue(Iterable<Item> items)
      Construct a linked queue containing the given items.
      Parameters:
      items - the items
    • LinkedQueue

      @SafeVarargs public LinkedQueue(Item... items)
      Construct a linked queue containing the given items.
      Parameters:
      items - the items
  • Method Details

    • enqueue

      public void enqueue(Item item)
      Description copied from interface: Queue
      Enqueue (insert) the given item to the back.
      Specified by:
      enqueue in interface Queue<Item>
      Parameters:
      item - the new back item
    • dequeue

      public Item dequeue() throws NoSuchElementException
      Description copied from interface: Queue
      Dequeue (remove and return) the given item from the front.
      Specified by:
      dequeue in interface Queue<Item>
      Returns:
      the old front item
      Throws:
      NoSuchElementException - if there's no first item to remove (i.e. if this is empty)
    • front

      public Item front() throws NoSuchElementException
      Description copied from interface: Queue
      Get the item at the front.
      Specified by:
      front in interface Queue<Item>
      Returns:
      the front item
      Throws:
      NoSuchElementException - if there's no first item to retrieve (i.e. if this is empty)
    • size

      public int size()
      Description copied from interface: Container
      Get the number of contained items.
      Specified by:
      size in interface Container<Item>
      Returns:
      the size
    • items

      public Iterable<Item> items()
      Description copied from interface: Container
      Get an iterable that yields each item once.
      Specified by:
      items in interface Container<Item>
      Returns:
      an iterable over the items