Linear Data Structure 491
14.17 REPRESENTATION OF QUEUE
The queue can be put into operation in two ways,
a) Static implementation : Static implementation means array implementation. In this
implementation, we should be assured of the number of elements we want in the queue. The
size of the array is decided before execution at compile time. Once the array is declared, its size
cannot be altered. The array at run time neither enlarged nor shrunk. The beginning of the
array, that is, Oth element is the front and the last memory location will be rear of the queue. A
queue can be declared as an array of any data type.
int queue[7];
In the above statement, an array queue [] of integer type is declared.
Front
5 4
00
7
3
00
Rear
Fig. 14.16 Queues
From Fig.14.16 we can say that first six locations of a queue are filled and the remaining two are
vacant. The element 5 is at front and 8 is at rear.
1) If the value of front element is zero, then queue is empty.
2) If the value of queue [6] is non-zero then the queue is full.
3) When an element is inserted, the position of rear increases.
4) When an element is deleted from the queue, the value of front increases by one.
5) When we continuously insert elements in the queue the elements are shifted from front to rear.
For the first two points, it assumed that we follow the fifth point.
Consider the following program.
14.11 Write a program to implement a queue using an array.
# include <stdio.h>
# include cconio.h>
# include cprocess.h>
main ()
{
int queue[8];
int rear»0;
clrscrO ;
while(1)
{
printf ("Enter element : " );
scanf ( ”%d",& queue[rear]);
rear++;