const queue = [];
queue.push(1); queue.push(2);
queue.shift(); // 1 β first in, first outA queue uses push/shift for FIFO (First In, First Out) behavior.
A Queue is a First-In-First-Out (FIFO) data structure where elements are added at the back and removed from the front.
Operations:
enqueue(x): Add element x to the backdequeue(): Remove and return the front elementsize: Number of elementsReal-world example: Printer queue (first document printed is the first one sent to printer).
class Queue {
enqueue(x: any): void {}
dequeue(): any {}
get size(): number {}
}
const q = new Queue()
q.enqueue(1)
q.enqueue(2)
q.dequeue() // 1