The queue ADT stores a collection of arbitrary elements. Insertions and deletions follow FIFO. The elements are arranged in a sequence. Insertions are at the rear of the queue and removals are at the front.

Main queue operations:

  • enqueue(e): inserts element at the end of the queue
  • dequeue(): removes and returns the element at the front of the queue

Auxiliary queue operations:

  • front(): returns the element at the front without removing it
  • size(): returns the number of elements stored
  • isEmpty(): returns a boolean value indicating whether no elements are stored

Exceptions:

  • Attempting dequeue or front on an empty queue throws EmptyQueueException.

Queue Interface in Java

Below is a Java interface according to our queue ADT:

public interface Queue<E> {
	public int size();
	public boolean isEmpty();
	public E front() throws EmptyQueueException;
	public void enqueue(E element);
	public E dequeue() throws EmptyQueueException;
}