-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathMaximum Element
More file actions
77 lines (67 loc) · 1.14 KB
/
Copy pathMaximum Element
File metadata and controls
77 lines (67 loc) · 1.14 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
73
74
75
76
77
#include <stdio.h>
#include <string.h>
#include <math.h>
#include <stdlib.h>
#include <limits.h>
int MAX=100000;
int stack[100000],stack2[100000];
int top=-1;
void push(int x)
{
stack2[-1]=INT_MIN;
if(top==MAX-1)
printf("overflow \n");
else
{
stack[++top]=x;
if(x>stack2[top-1])
stack2[top]=x;
else
stack2[top]=stack2[top-1];
}
}
int pop()
{
int x;
if(top==-1){
printf("underflow \n");
return -1;
}
else
x=stack[top--];
return x;
}
int pop2()
{
int x,top2=top;
if(top2==-1){
printf("underflow \n");
return -1;
}
else
x=stack2[top2--];
return x;
}
int main()
{
int x,value,T,t=0;
scanf("%d",&T);
do{
scanf("%d",&x);
t++;
switch(x){
case 1:
//printf("enter value to be pushed");
scanf("%d",&value);push(value);
break;
case 2:pop();
break;
case 3:printf("%d\n",pop2());
break;
case 4:break;
default: printf("Invalid case");
break;
}
}while(T!=t);
return 0;
}