Queue Data Structure Implementation Using an Array

Write a program to implement queue data structure using an array.  In my previous posts, I have explained Stack and Linked List data structure. In this post, We’ll learn about queue data structure and their implementation.

Queue Data Structure

In Queue data structure, An element is inserted at one end called rear and deleted at other end called front. As compared to stack in which insertion and deletion are allowed only at one end. It is also called FIFO (First In First out).

Enqueue – In queue insertion operation is called as enqueue.

Dequeue – Delete operation is called as Dequeue

Linked List Data Structure

Program to implement stack using array

Subscribe Our Tutorials

Get Latest Updates on Facebook

Queue Data Structure Implementation Using an Array

Let’s implement queue data structure using an array. To implement queue data structure, we need to take two variables to keep track of both ends.

rear – points an index of last added item.

front – points to the first item in the queue.

MCQ on Stack and Queue

Implementation Logic

1. Initialize rear = front = -1.  Initially, Queue is empty so rear and front both have assigned a value -1.

2. To insert new data, rear should be incremented by 1. If the front index is -1, then front is incremented and set to 0.

3. If any element is deleted from queue, then the value of front should be incremented by 1.

Data Structure Books

Recommended Books on Data Structure


About WebRewrite

I am technology lover who loves to keep updated with latest technology. My interest field is Web Development.
Tagged , , . Bookmark the permalink.