Queue using Array in C++

The queue is a linear data structure that has the following properties:-

  • It works on the principle of FIFO (First In First Out)
  • It has mainly 2 pointers to perform operations: Front & Rear. The Rear is for insertion and the Front is for deletion
  • It is a linear data structure that gives sequential one-way access to the elements. Even though we can implement it using an array, we cannot access any element through indices directly because access to elements is given only through the rear and front pointers.

To understand better about the queue data structure let us go through the following diagram which describes the workflow of the queue implemented using an array:


Explanation:

  1. Initially our array based Queue consists of : [10, 30, 40, 50, 40, 60]
  2. And then we perform an Enqueue and a Dequeue Operation for element 10 and 15 respectively.
  3. After performing operations, our final queue is : [30, 40, 50, 40, 60, 15]

Representation of Queue in C++

We can represent a queue using a class that contains:

  • An array to store the data.
  • Front and back index pointer.
  • Constructor to initialize the queue.
  • Member functions that provide enqueue and dequeue operations.

C++ Program to Implement Queue using Array

A queue is a linear data structure that consists of elements arranged in a sequential order where one end is used to add elements, and another for removing them which results in the FIFO (First-In First-Out) order of operations. In this article, we will learn how to write a program to implement queues using an array in C++.

Similar Reads

Queue using Array in C++

The queue is a linear data structure that has the following properties:-...

Basic Operations on Queue in C++

In order to implement a queue using array, we must be aware of the basic operations that are performed in a queue to manipulate the elements present inside it. Following are the basic operations of the queue data structure:...

C++ Program to Implement Queue using Array

The following program demonstrates how we can implement a queue using array in C++:...

Applications of Queue

Due to its FIFO nature, queue is a widely utilised data structure in a variety of real world applications :-...

Conclusion

In this article we’ve covered the most important aspects of Queue data structure like working, basic operations, implementation using array in C++, applications etc. We have also seen that the queue provide O(1) time and space complexity for all operation. Though the operations provide limited capablity....