Class ListQueue<E>

  • All Implemented Interfaces:
    Queue<E>

    public class ListQueue<E>
    extends java.lang.Object
    implements Queue<E>
    Provides an implementation of a Queue using a singly linked list:

    All operations require constant time in the worst case.
    • Constructor Summary

      Constructors 
      Constructor Description
      ListQueue()
      Creates a linked list representing an empty queue.
    • Method Summary

      All Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      void insert​(E x)
      Inserts a new object onto the queue.
      boolean isEmpty()
      Reports whether the queue is currently empty without changing it.
      E peek()
      Reports the front element of the queue without changing it.
      E remove()
      Removes an element from the front of the stack and reports it.
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
    • Constructor Detail

      • ListQueue

        public ListQueue()
        Creates a linked list representing an empty queue.
    • Method Detail

      • insert

        public void insert​(E x)
        Description copied from interface: Queue
        Inserts a new object onto the queue.
        Specified by:
        insert in interface Queue<E>
        Parameters:
        x - the object to be pushed onto the queue

        Precondition:
        1. The Queue Invariant is satisfied.
        2. An element x of type E has been given as input.
        Postcondition:
        1. The Queue Invariant is satisfied.
        2. The input object x has been inserted at the rear of the queue (which is otherwise unchanged).
      • peek

        public E peek()
        Description copied from interface: Queue
        Reports the front element of the queue without changing it.
        Specified by:
        peek in interface Queue<E>
        Returns:
        the element at the front of the queue
      • remove

        public E remove()
        Description copied from interface: Queue
        Removes an element from the front of the stack and reports it.
        Specified by:
        remove in interface Queue<E>
        Returns:
        the element removed from the queue
      • isEmpty

        public boolean isEmpty()
        Description copied from interface: Queue
        Reports whether the queue is currently empty without changing it.
        Specified by:
        isEmpty in interface Queue<E>
        Returns:
        true if the queue is empty, and false otherwise

        Precondition:
        1. The Queue Invariant is satisfied.
        Postcondition:
        1. The Queue Invariant is satisfied.
        2. The queue is not changed.
        3. If the queue was empty before this operation then “true” is returned as output.
        4. If the queue was not empty before this operation then “false” is returned as output.