Skip to content

Commit 157c2d5

Browse files
authored
Merge pull request kothariji#565 from sudarshandpai/patch-1
Create 155.Min Stack.cpp
2 parents 56b6641 + 48f823d commit 157c2d5

File tree

1 file changed

+37
-0
lines changed

1 file changed

+37
-0
lines changed
Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
class MinStack {
2+
public:
3+
/** initialize your data structure here. */int arr[9999],min,tp;
4+
MinStack() {
5+
tp=-1;
6+
}
7+
8+
void push(int x) {
9+
tp++;
10+
arr[tp]=x;
11+
cout<<tp<<" push\n";
12+
13+
}
14+
15+
void pop() {
16+
--tp;
17+
cout<<tp<<" pop\n";
18+
19+
}
20+
21+
int top() {
22+
cout<<tp<<" top\n";
23+
return arr[tp];
24+
25+
}
26+
27+
int getMin() {
28+
cout<<tp<<" min\n";
29+
min = INT_MAX;
30+
for(int i = 0;i<=tp;i++)
31+
{
32+
if(min>arr[i])
33+
min = arr[i];
34+
}
35+
return min;
36+
}
37+
};

0 commit comments

Comments
 (0)