Interface Queue<E>

Type Parameters:
E - the element type
All Known Subinterfaces:
CircularQueue<E>
All Known Implementing Classes:
ArrayQueue, LinkedCircularQueue, LinkedQueue

public interface Queue<E>
Interface for a queue: a collection of elements that are added and removed according to the first-in first-out principle. Although similar in purpose, this interface differs from java.util.Queue.
  • Method Summary

    Modifier and Type
    Method
    Description
    Removes and returns the first element of the queue.
    void
    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.
  • Method Details

    • size

      int size()
      Returns the number of elements in the queue.
      Returns:
      number of elements in the queue
    • isEmpty

      boolean isEmpty()
      Tests whether the queue is empty.
      Returns:
      true if the queue is empty, false otherwise
    • enqueue

      void enqueue(E e)
      Adds an element at the rear of the queue.
      Parameters:
      e - the element to be added
    • first

      E first()
      Returns, but does not remove, the first element of the queue.
      Returns:
      the first element of the queue (or null if empty)
    • dequeue

      E dequeue()
      Removes and returns the first element of the queue.
      Returns:
      element removed (or null if empty)