Queue Data Structure Implementation Using an Array

Write a program to implement a queue using an array.  In this tutorial, You are going to learn about Queue data structure and their implementation using an array in C, C++ & Java. In my previous posts, I have explained Stack and Linked List data structure.

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 data structure in which insertion and deletion are allowed only at one end. Queue data structure is also called FIFO (First In First out).

Enqueue – In queue, insertion operation is called as enqueue.

Dequeue – In queue, delete operation is called as Dequeue

Linked List Data Structure

Program to implement stack using array

Queue Data Structure Implementation Using an Array

In this tutorial, We’ll implement a Queue using an array. To implement queue using an array, we need to take two variables to keep track of both ends.

rear – points an index of last added item.

front – points an index of last removed item.

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 a 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 a queue, then the value of front should be incremented by 1.

Implement a Queue using an Array in C

Now you have understood what is Queue data structure and it’s basic terminologies. Let’s implement a queue data structure in C.

 

Implement a Queue using an Array in Java

Data Structure Books

Recommended Books on Data Structure

Tagged , , . Bookmark the permalink.

About WebRewrite

I am technology lover who loves to keep updated with latest technology. My interest field is Web Development.