Theory
A queue follows the First In, First Out principle. The element that enters first is removed first. Queues are commonly used in scheduling, task processing, printer queues and breadth-first search.
Example
const queue = [];
queue.push("A");
queue.push("B");
queue.push("C");
console.log(queue.shift());
console.log(queue);
Expected Output
A is removed first because the queue follows FIFO.
Practice
Implement a queue with enqueue and dequeue operations.
Interview Questions
- What is a queue?
- What does FIFO mean?
- What are enqueue and dequeue?
- Where are queues used?