# Length of Array 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 length()
{
printf("Length of queue is %d",rear-front+1);
}

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();
length();
}

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
Length of queue is 5

-In this program, we have two function insert() and display(),length()
- 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.
- length() : is used to display the length of the queue.