-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathswap().cpp
47 lines (39 loc) · 905 Bytes
/
swap().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
// CPP program to illustrate Implementation of swap() function
#include <iostream>
using namespace std;
void print(priority_queue<int> pq)
{
while (!pq.empty()) {
cout << pq.top() << " ";
pq.pop();
}
cout << endl;
}
int main()
{
priority_queue<int> pq1;
priority_queue<int> pq2;
// pushing elements into the 1st priority queue
pq1.push(1);
pq1.push(2);
pq1.push(3);
pq1.push(4);
// pushing elements into the 2nd priority queue
pq2.push(3);
pq2.push(5);
pq2.push(7);
pq2.push(9);
cout << "Before swapping:-" << endl;
cout << "Priority Queue 1 = ";
print(pq1);
cout << "Priority Queue 2 = ";
print(pq2);
// using swap() function to swap elements of priority queues
pq1.swap(pq2);
cout << endl << "After swapping:-" << endl;
cout << "Priority Queue 1 = ";
print(pq1);
cout << "Priority Queue 2 = ";
print(pq2);
return 0;
}