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 queuedequeue(): removes and returns the element at the front of the queue
Auxiliary queue operations:
front(): returns the element at the front without removing itsize(): returns the number of elements storedisEmpty(): returns a boolean value indicating whether no elements are stored
Exceptions:
- Attempting
dequeueorfronton an empty queue throwsEmptyQueueException.
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;
}