Class LinkedDeque<E>

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

public class LinkedDeque<E> extends Object implements Deque<E>
Realization of a double-ended queue as an adaptation of a DoublyLinkedList. 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
    void
    addFirst(E element)
    Adds an element at the front of the queue.
    void
    addLast(E element)
    Adds an element at the back of the queue.
    Returns, but does not remove, the first element of the queue.
    boolean
    Tests whether the queue is empty.
    Returns, but does not remove, the last element of the queue.
    Removes and returns the first element of the queue.
    Removes and returns the last element of the queue.
    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

    • LinkedDeque

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

    • size

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

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

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

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

      public void addFirst(E element)
      Adds an element at the front of the queue.
      Specified by:
      addFirst in interface Deque<E>
      Parameters:
      element - the element to be added
    • addLast

      public void addLast(E element)
      Adds an element at the back of the queue.
      Specified by:
      addLast in interface Deque<E>
      Parameters:
      element - the element to be added
    • removeFirst

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

      public E removeLast()
      Removes and returns the last element of the queue.
      Specified by:
      removeLast in interface Deque<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