-
Notifications
You must be signed in to change notification settings - Fork 7
/
stacks.cpp
44 lines (34 loc) · 866 Bytes
/
stacks.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
// works on lifo methodology
#include <iostream>
#include <stack>
using namespace std;
int main(){
// declaration
stack<string> st;
// assigning value
st.push("Adarsh");
st.push("Navneet");
st.push("Sinha");
// printing our stack
cout<<"top element is "<<st.top()<<endl;
// size of stack
cout<<"size of stack is "<<st.size()<<endl;
// stack is empty or not
cout<<"Is the stack empty?"<<st.empty()<<endl;
// removing the top element
st.pop();
cout<<"Now the top is "<<st.top()<<endl;
// printing the complete stack
// inserting new elements
st.push("Computer");
st.push("Science");
st.push("Engineering");
int n = st.size();
cout<<"The complete stack is ";
for(int i=0; i<n; i++){
cout<<st.top()<<" ";
st.pop();
}
cout<<endl;
return 0;
}