Queue

A queue is a linear data structure that follows the FIFO principle

A queue is a simple, linear data structure that follows the First In, First Out (FIFO) principle. This means that the first element added to the queue will be the first one to be removed.

Key Concept

FIFO Principle (First In, First Out): The first element added to the queue will be the first one to be removed.

Example: Think of a line at a ticket counter. When a person joins the line, they stand at the back. To be served, the person at the front of the line is attended to first, and others move forward in order.

Key Terms in Queue

Enqueue:

The operation of adding an element to the end (rear) of the queue.

Dequeue:

The operation of removing an element from the front of the queue.

Front:

The first element in the queue, which is the next to be dequeued.

Rear (or Back):

The last element in the queue, where new elements are added.