Search⌘ K
AI Features

What is a Queue?

Explore the concept of queues as a fundamental linear data structure that operates on the FIFO principle. Learn how queues manage elements with enqueue and dequeue operations, understand different queue types including linear, circular, priority, and double-ended queues, and discover their practical applications in operating systems and networking.

Introduction

Similar to the stack, a queue is another linear data structure that stores the elements in a sequential manner. The only significant difference between stacks and queues is that instead of using the LIFO principle, queues implement the FIFO method which is short for First in First Out.

According to FIFO, the first element inserted is the one that comes out first. You can think of a queue as a pipe with two ends called front and rear / back. Elements from a queue are always deleted from the front and added at the rear. The following animation illustrates the structure of a queue.

Queues are slightly trickier to implement as compared to stacks because we have to keep track of both ends of the array. The elements are inserted from the back and removed from the front.

A perfect real-life example of a queue is a line of people waiting to get a ticket from ...