forked from cyberpvn7/Python_Lang
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdivyansh99.cpp
More file actions
42 lines (36 loc) · 810 Bytes
/
divyansh99.cpp
File metadata and controls
42 lines (36 loc) · 810 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
// CPP program to illustrate
// Implementation of swap() function
#include <stack>
#include <iostream>
using namespace std;
int main()
{
// stack container declaration
stack<int> mystack1;
stack<int> mystack2;
// pushing elements into first stack
mystack1.push(1);
mystack1.push(2);
mystack1.push(3);
mystack1.push(4);
// pushing elements into 2nd stack
mystack2.push(3);
mystack2.push(5);
mystack2.push(7);
mystack2.push(9);
// using swap() function to swap elements of stacks
mystack1.swap(mystack2);
// printing the first stack
cout<<"mystack1 = ";
while (!mystack1.empty()) {
cout<<mystack1.top()<<" ";
mystack1.pop();
}
// printing the second stack
cout<<endl<<"mystack2 = ";
while (!mystack2.empty()) {
cout<<mystack2.top()<<" ";
mystack2.pop();
}
return 0;
}