Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <bits/stdc++.h>
- #include <ext/pb_ds/assoc_container.hpp>
- #include <ext/pb_ds/priority_queue.hpp>
- using namespace std;
- using namespace __gnu_pbds;
- typedef __gnu_pbds::priority_queue<int, less<int>, pairing_heap_tag> heap;
- int main()
- {
- int arr1[] = {9, 0, 1, 2, 5, 3, 4, 7, 6, 8};
- int arr2[] = {19, 10, 11, 12, 15, 13, 14, 17, 16, 18};
- heap pq1, pq2;
- //push()
- for(auto it : arr1)
- pq1.push(it);
- for(auto it : arr2)
- pq2.push(it);
- //top(), pop(), size(), empty()
- printf("pq1: ");
- while(pq1.size())
- {
- printf("%d ", pq1.top());
- pq1.pop();
- }
- puts("");
- printf("pq2: ");
- while(!pq2.empty())
- {
- printf("%d ", pq2.top());
- pq2.pop();
- }
- puts("");
- //push()
- for(auto it : arr1)
- pq1.push(it);
- for(auto it : arr2)
- pq2.push(it);
- //join()
- pq1.join(pq2);
- printf("pq1.join(pq2): ");
- while(pq1.size())
- {
- printf("%d ", pq1.top());
- pq1.pop();
- }
- puts("");
- return 0;
- }
- /**
- OUTPUT:
- pq1: 9 8 7 6 5 4 3 2 1 0
- pq2: 19 18 17 16 15 14 13 12 11 10
- pq1.join(pq2): 19 18 17 16 15 14 13 12 11 10 9 8 7 6 5 4 3 2 1 0
- **/
Add Comment
Please, Sign In to add comment