Minimum 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 minimum()
{
int min=queue[0];
int i;
for(i=front;i< rear;i++)
if(queue[i]< min)
min=queue[i];
printf("Minimum in Queue is %d",min);
}

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

output-

Number of element want to enter in queue
5
Enter the element in queue
6
Enter the element in queue
1
Enter the element in queue
4
Enter the element in queue
3
Enter the element in queue
9
Queue is :
6 1 4 9 3
Minimum in Queue is 1

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