-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathSpecialStack.cpp
75 lines (67 loc) · 1.17 KB
/
SpecialStack.cpp
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
// { Driver Code Starts
#include<iostream>
#include<stack>
using namespace std;
void push(stack<int>& s,int a);
bool isFull(stack<int>& s,int n);
bool isEmpty(stack<int>& s);
int pop(stack<int>& s);
int getMin(stack<int>& s);
//This is the STL stack (http://quiz.geeksforgeeks.org/stack-container-adaptors-the-c-standard-template-library-stl/).
stack<int> s;
int main(){
int t;
cin>>t;
while(t--){
int n,a;
cin>>n;
while(!isEmpty(s)){
pop(s);
}
while(!isFull(s,n)){
cin>>a;
push(s,a);
}
cout<<getMin(s)<<endl;
}
}// } Driver Code Ends
void push(stack<int>& s, int a){
// Your code goes here
s.push(a);
}
bool isFull(stack<int>& s,int n){
// Your code goes here
if(s.size()==n)
return true;
else
return false;
}
bool isEmpty(stack<int>& s){
// Your code goes here
if(s.size()==0)
return true;
else
return false;
}
int pop(stack<int>& s){
// Your code goes here
int x=s.top();
s.pop();
return x;
}
int getMin(stack<int>& s){
// Your code goes here
int minele=2324343;
if(s.size()==0)
return -1;
else
{ while(!s.empty())
{
int temp=s.top();
s.pop();
if(temp<minele)
minele=temp;
}
}
return minele;
}