-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathds-stl-stack.cpp
49 lines (39 loc) · 1.02 KB
/
ds-stl-stack.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
#include <iostream>
#include <stack>
using namespace std;
// define a stack container which will
// contain integers only
stack<int>Stk;
int main(void)
{
freopen("ds-stl-stack.input", "r", stdin);
int T, N, tcase=1;
cin>>T;
int num;
while(T--) {
cin>>N;
for(int i = 0; i < N; i++) {
cin>>num;
Stk.push(num);
}
cout<<"#"<<tcase++<<endl;
cout<<"stack size = "<<Stk.size()<<endl;
cout<<"top element = "<<Stk.top()<<endl;
cout<<"popped\n";
Stk.pop();
cout<<"popped\n";
Stk.pop();
cout<<"popped\n";
Stk.pop();
cout<<"stack size = "<<Stk.size()<<endl;
cout<<"top element = "<<Stk.top()<<endl;
// let's pop all elements until stack is empty
cout<<"popping all elements until stack is empty\n";
while(!Stk.empty()) {
cout<<Stk.top()<<" ";
Stk.pop();
}
cout<<endl;
cout<<"stack size = "<<Stk.size()<<endl;
}
}