DSA Lesson 12 of 33

Queue

Learn the FIFO data structure and its applications.

Course Progress36%

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

  1. What is a queue?
  2. What does FIFO mean?
  3. What are enqueue and dequeue?
  4. Where are queues used?