Maximum 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 del

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

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


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
9
Enter the element in queue
3
Queue is :
1 6 4 9 3
Maximum in Queue is 9

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




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

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


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
9
Enter the element in queue
3
Queue is :
1 6 4 9 3
Maximum in Queue is 9

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




Leave a Comment:
Search
R4R Team
R4Rin Top Tutorials are Core Java,Hibernate ,Spring,Sturts.The content on R4R.in website is done by expert team not only with the help of books but along with the strong professional knowledge in all context like coding,designing, marketing,etc!