-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathstack.cpp
More file actions
33 lines (26 loc) · 746 Bytes
/
Copy pathstack.cpp
File metadata and controls
33 lines (26 loc) · 746 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
#include <bits/stdc++.h>
using namespace std;
int main(){
stack<int>s;
//push() operation
s.push(1);
s.push(2);
s.push(3);
s.push(4);
s.push(5);
//swap operation-swaps two stacks
stack<int>s2;
s2.swap(s);
while(!s2.empty()){ //empty shows stack is empty or not
cout<<s2.top()<<" " ; //top() gives top element of stack
s2.pop(); //deletes element in stack
}
cout<<endl;
cout<<"Size:"<<s.size()<<endl;
//traversing stack
while(!s.empty()){ //empty shows stack is empty or not
cout<<s.top()<<" " ; //top() gives top element of stack
s.pop(); //deletes element in stack
}
cout<<endl;
}