forked from sanketpatil02/Code-Overflow
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathLargestElmQueue.c
More file actions
72 lines (67 loc) · 1.09 KB
/
LargestElmQueue.c
File metadata and controls
72 lines (67 loc) · 1.09 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
#include<stdio.h>
#include<stdlib.h>
void insert(int Q[],int *front,int *rear,int size)
{
int val;
if(*front==-1)
{
*front=0;
*rear=0;
}
else if(*rear==size-1)
{
printf("\nOverflow");
}
else
{
*rear=*rear+1;
}
printf("\nEnter the value: \n");
scanf("%d",&val);
Q[*rear]=val;
}
void del(int Q[],int *front,int *rear,int size)
{
int n;
if(*front==-1||*front>*rear)
{
printf("\nUnderflow");
}
else
{
++*front;
}
}
void display(int Q[],int *front,int *rear)
{
if(*front==-1)
{
printf("");
exit(0);
}
else
{ printf("\nQUEUE :\n");
for(int i=*front;i<=*rear;i++)
{printf("\t%d \t\n",Q[i]);}
}
}
int MAX(int Q[],int *front,int *rear,int size)
{ int max=Q[*front];
while(*front<=*rear)
{ if(Q[*front]>max)
{max=Q[*front];}
del(Q,&(*front),&(*rear),size);
}
return max;
}
main()
{
int Q[20],s,size,front=-1,rear=-1,val,temp[20];
printf("\nEnter the size of queue : ");
scanf("%d",&size);
for(int i=0;i<size;i++)
{insert(Q,&front,&rear,size);}
display(Q,&front,&rear);
int max=MAX(Q,&front,&rear,size);
printf("\nLARGEST NO. IN QUEUE: %d",max);
}