-
Notifications
You must be signed in to change notification settings - Fork 8
/
Copy path25 may 2020 stacks
135 lines (116 loc) · 1.84 KB
/
25 may 2020 stacks
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
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
//Basicsof stacks
#include <iostream>
#include <stack>
using namespace std;
void print(stack<char> s)
{
while(!s.empty())
{
cout<<s.top()<<" ";
s.pop();
}
}
string reverse(string s)
{
stack<char> st;
for(int i=0;i<s.size();i++)
{
st.push(s[i]);
}
for(int i=0;i<s.size();i++)
{
s[i]=st.top();
st.pop();
}
return s;
}
int main() {
stack<stack<int>> x;
stack<int> d;
d.push(10);
d.push(20);
d.push(30);
x.push(d);
stack<int> c;
c.push(30);
c.push(40);
x.push(c);
// x.push(c.push(50));
while(!x.empty())
{
cout<<"\n";
stack<int> z = x.top();
while(!z.empty())
{
cout<<z.top()<<" ";
z.pop();
}
x.pop();
}
}
//minimum value of the stack
#include <iostream>
#include<stack>
using namespace std;
void add(stack<int> &m, stack<int> &a,int data)
{
if(m.empty())
{
m.push(data);
a.push(data);
return;
}
int z = a.top();
if(z>data)
{
m.push(data);
a.push(data);
}
else
{
m.push(data);
a.push(z);
}
}
void print(stack<int> m, stack<int> a)
{
cout<<"Main Stack: ";
while(!m.empty())
{
cout<<m.top()<<" " ;
m.pop();
}
cout<<"\nAux stack: ";
while(!a.empty())
{
cout<<a.top()<<" ";
a.pop();
}
}
void remove(stack<int> &m, stack<int> &a)
{
if(m.empty())
{
cout<<"Stack is empty\n";
return ;
}
m.pop();
a.pop();
}
int getmin(stack<int> a)
{
if(a.empty())
return -1;
return a.top();
}
int main() {
stack<int> m;
stack<int> a;
add(m,a,10);
add(m,a,20);
add(m,a,5);
add(m,a,1);
remove(m,a);
int z= getmin(a);
cout<<z<<" ";
}