-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathprogram.cpp
More file actions
45 lines (44 loc) · 883 Bytes
/
program.cpp
File metadata and controls
45 lines (44 loc) · 883 Bytes
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
#include "../include/pre.h"
#include <stack>
#include <limits>
class MinStack
{
private:
std::stack<int> data;
std::stack<int> min;
public:
void push(int x) {
data.push(x);
if (getMin() >= x) min.push(x);
}
void pop() {
if (top() == min.top()) min.pop();
data.pop();
}
int top() {
return data.top();
}
int getMin() {
return min.empty() ? std::numeric_limits<int>::max() : min.top();
}
};
int Mymain()
{
MinStack s;
s.push(9000);
cout << s.getMin() << endl;
s.push(10);
cout << s.getMin() << endl;
s.pop();
cout << s.getMin() << endl;
s.push(50);
cout << s.getMin() << endl;
s.pop();
cout << s.getMin() << endl;
s.push(1);
cout << s.getMin() << endl;
s.pop();
cout << s.getMin() << endl;
s.pop();
cout << s.getMin() << endl;
}