Expt 5 Implement Linear Queue ADT using array
Expt 5 Implement Linear Queue ADT using array
_____________________________________________________________________________________
Experiment No. 5
Criteria Points
Correctness of the program
Clarity of documentation
Delivery
Total
Rizvi College of Engineering, Mumbai
_____________________________________________________________________________________
Theory: A queue data structure can be implemented using a one dimensional array. The queue
implemented using an array stores only a fixed number of data values. The implementation of queue data
structure using arrays is very simple. Just define a one dimensional array of specific size and insert or delete
the values into that array by using FIFO (First In First Out) principle with the help of variables 'front' and
'rear'. Initially both 'front' and 'rear' are set to -1. Whenever, we want to insert a new value into the queue,
increment the 'rear' value by one and then insert at that position. Whenever we want to delete a value from
the queue, then delete the element which is at 'front' position and increment 'front' value by one.
Algorithm:
Creation of Queue
Before we implement actual operations, first follow the below steps to create an empty queue.
● Step 1 - Include all the header files which are used in the program and define a constant 'SIZE' with
specific value.
● Step 2 - Declare all the user defined functions which are used in queue implementation.
● Step 3 - Create a one dimensional array with above defined SIZE (int queue[SIZE])
● Step 4 - Define two integer variables 'front' and 'rear' and initialize both with '-1'. (int front = -1,
rear = -1)
● Step 5 - Then implement the main method by displaying a menu of operations list and make suitable
function calls to perform operations selected by the user on queue.
parameter. We can use the following steps to delete an element from the queue...
● Step 1 - Check whether the queue is EMPTY. (is front > rear or front = rear = -1)
● Step 2 - If it is EMPTY, then display "Queue is EMPTY! Deletion is not possible!" and terminate
the function.
● Step 3 - If it is NOT EMPTY, then increment the front value by one (front ++). Then display
queue[front] as a deleted element. Then check whether front is greater than rear (is front >rear ?),
if it TRUE, then set both front and rear to '-1' (front = rear = -1).
● Step 1 - Check whether the queue is EMPTY. (is front > rear or front = rear = -1) ● Step 2 - If it
is EMPTY, then display "Queue is EMPTY" and terminate the function.
● Step 3 - If it is NOT EMPTY, then define an integer variable 'i' and set 'i = front'.
● Step 4 - Display 'queue[i]' value and increment 'i' value by one (i++). Repeat the same until 'i' value
reaches to rear (i <= rear)
#include <stdlib.h>
#define SIZE 10
1:
exit(0); default:
} void deQueue()
printf("%d\t", queue[i]);
CO Covered: