Skip to content

Commit ece09bc

Browse files
committed
maximum element file
1 parent 51ad5be commit ece09bc

File tree

1 file changed

+104
-0
lines changed

1 file changed

+104
-0
lines changed

Stack/Maximum_element.cpp

Lines changed: 104 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,104 @@
1+
/*
2+
written by Pankaj Kumar.
3+
country:-INDIA
4+
*/
5+
#include <bits/stdc++.h>
6+
#include <ext/pb_ds/assoc_container.hpp>
7+
#include <ext/pb_ds/tree_policy.hpp>
8+
using namespace std;
9+
using namespace __gnu_pbds;
10+
typedef long long ll ;
11+
typedef vector<ll> vl;
12+
#define speed cin.tie(0);cout.tie(0);ios_base::sync_with_stdio(0);
13+
// define values.
14+
// #define mod 1000000007
15+
#define phi 1.618
16+
/* Abbrevations */
17+
#define ff first
18+
#define ss second
19+
#define mp make_pair
20+
#define line cout<<endl;
21+
#define pb push_back
22+
#define Endl "\n"
23+
// loops
24+
#define forin(arr,n) for(ll i=0;i<n;i++) cin>>arr[i];
25+
// Some print
26+
#define no cout<<"NO"<<endl;
27+
#define yes cout<<"YES"<<endl;
28+
#define cc ll test;cin>>test;while(test--)
29+
// sort
30+
#define all(V) (V).begin(),(V).end()
31+
#define srt(V) sort(all(V))
32+
#define srtGreat(V) sort(all(V),greater<ll>())
33+
#define printv(v) for(ll i=0;i<ll(v.size());i++){cout<<v[i]<<" ";} line;
34+
/* ONLINE JUDGE */
35+
// #ifdef ONLINE_JUDGE
36+
// freopen("input.txt", "r", stdin);freopen("output.txt", "w", stdout);
37+
// #endif
38+
// function
39+
40+
ll power(ll x,ll y,ll mod)
41+
{
42+
ll res=1;
43+
// x=x%mod;
44+
while(y>0)
45+
{
46+
if(y%2==1)
47+
{
48+
res*=x;
49+
// res=res%mod;
50+
}
51+
y/=2; x*=x; // x=x%mod;
52+
}
53+
return res;
54+
}
55+
// datatype definination
56+
#define ordered_set tree<ll,null_type,less<ll>,rb_tree_tag,tree_order_statistics_node_update>
57+
58+
/* ascii value
59+
A=65,Z=90,a=97,z=122
60+
*/
61+
/* -----------------------------------------------------------------------------------*/
62+
63+
ll solve()
64+
{
65+
cout<<"No of operation "<<;
66+
ll q;
67+
cin>>q;
68+
stack<pair<ll,ll>> st;
69+
ll maxo=0;
70+
while(q--)
71+
{
72+
cout<<"1.for updation\n2.pop top element\n3.maximum element in stack"<<endl;
73+
ll a;
74+
cin>>a;
75+
if(a==1)
76+
{
77+
ll x;
78+
cout<<"enter element ";
79+
cin>>x;
80+
if(st.size()>0)
81+
st.push({x,max(st.top().ss,x)});
82+
else
83+
st.push({x,max(0LL,x)});
84+
}
85+
else if(a==2)
86+
st.pop();
87+
else
88+
cout<<st.top().ss<<endl;
89+
}
90+
return 0;
91+
}
92+
93+
int main()
94+
{
95+
speed;
96+
//freopen("input.txt"a, "r", stdin);
97+
solve();
98+
}
99+
100+
/* stuff you should look before submission
101+
* int overflow
102+
* special test case (n=0||n=1||n=2)
103+
* don't get stuck on one approach if you get wrong answer
104+
*/

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy