# Front and rear difference in Queue by R4R Team

Queue implementation by Array:
We implement the queue using the Array in C, in which insertion is done at rear side and deletion is done at front side.

program-

#include< stdio.h>
#include< conio.h>
#define MAX 50

int queue[MAX];
int front=-1, rear=-1;

void insert()
{
int n;
if (rear == MAX - 1)
printf("Queue Overflow \n");
else
{
if (front == - 1)
front = 0;
printf("Enter the element in queue");
scanf("%d",&n);
rear = rear + 1;
queue[rear] = n;
}
}

void display()
{
int i;
if (front==-1)
printf("Queue is empty n");
else
{
printf("Queue is : n");
for (i =front; i< = rear; i++)
printf("%d ", queue[i]);
}
}

void diff()
{
printf("Difference between front and rear in Queue is %d",rear-front);
}

void main()
{
int num,i;
printf("Number of element want to enter in queuen");
scanf("%d",&num);
for(i=0;i< num;i++){
insert();
}
display();
diff();
}

output-

Number of element want to enter in queue
5
Enter the element in queue
1
Enter the element in queue
6
Enter the element in queue
4
Enter the element in queue
3
Enter the element in queue
9
Queue is :
1 6 4 9 3
Difference between front and rear in Queue is 4

-In this program, we have two function insert() and display(),diff().
- insert() : is used to insert the element in queue at rear side
- display() : is used to display all element of queue from front to rear.
- diff() : is used to display difference between front and rear position.