> For the complete documentation index, see [llms.txt](https://tanias-workspace.gitbook.io/tanias-little-corner/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://tanias-workspace.gitbook.io/tanias-little-corner/data-structures/queue.md).

# Queue

A queue is a fundamental data structure in computer science that operates on a **First In, First Out (FIFO)** principle. This means that the first element added to the queue will be the first one to be removed. Here's a step-by-step explanation of the basic operations of a queue.

#### **Basic Operations**

**1. Enqueue**

* **Description:** Adds an element to the end of the queue.
* **Operation:** `queue.enqueue(element);` or `queue.push(element);`

**2.Dequeue**

* **Description:** Removes the element from the front of the queue.
* **Operation:** `queue.dequeue();` or `queue.pop();`

<figure><img src="/files/IF9AdfaNqaXI1mZHweE5" alt=""><figcaption></figcaption></figure>

**3.Front (or Peek)**

* **Description:** Returns the element at the front of the queue without removing it.
* **Operation:** `element = queue.front();`

**4. Is Empty**

* **Description:** Checks whether the queue is empty.
* **Operation:** `queue.empty();`

<figure><img src="/files/elOMqLBpj200rs60nesH" alt=""><figcaption></figcaption></figure>

* **Enqueue:** Add an element to the end of the queue.
* **Dequeue:** Remove the element from the front of the queue.
* **Front (Peek):** View the element at the front without removing it.
* **Is Empty:** Check if the queue is empty.
* **Size:** Get the number of elements in the queue.

#### **Real-World Example:**

* **Queue of Tasks:** Imagine a print queue in a computer system where print jobs are handled one at a time. The first job sent to the printer is the first one to be printed.
* **Queue in Banking:** When you go to a bank, the first customer who arrives is the first one to be served by the bank teller.
