What is a Queue?

This lesson gives an introduction to the queue data structure, its various uses, and types. We will also go through the inner workings of a Queue by briefly discussing each of its functions.

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.

Level up your interview prep. Join Educative to access 80+ hands-on prep courses.