-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathstack.cpp
More file actions
46 lines (32 loc) · 700 Bytes
/
stack.cpp
File metadata and controls
46 lines (32 loc) · 700 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
46
#include <stack>
#include <iostream>
using namespace std;
/*
* Remember
* 1. In C++, stack:: pop() only pops the top element but does not return it.
* 2. printing the array
* 3. st.empty()
*/
int main() {
stack<int> st;
cout<<"\nPushing element 20";
st.push(20);
cout<<"\nPushing element -2";
st.push(-5);
cout<<"\nPushing element 5";
st.push(5);
cout<<"\nTop element is "<<st.top();
cout<<"\nPop element "<<st.top();
st.pop();
cout<<"\nPop element "<<st.top();
st.pop();
cout<<"\nTop element is "<<st.top();
cout<<"\nPushing element 100";
st.push(100);
cout<<"\nPrinting the stack ";
while(!st.empty()) {
cout<<st.top()<<" ";
st.pop();
}
return 0;
}