Junior — Middle
Explain what a queue data structure is and how it works.
sobes.tech AI
Answer from AI
A queue is a data structure that operates on the FIFO (First In, First Out) principle, meaning the first entered element will be the first to be removed. Imagine a queue in a store: the first person to arrive is the first to be served.
Main operations:
- enqueue — adding an element to the end of the queue;
- dequeue — removing and retrieving an element from the front of the queue;
- peek/front — viewing the first element without removing it.
In Node.js, a queue is often used to manage asynchronous tasks to process them sequentially.