Emiliatan

pb_ds priority_queue

May 21st, 2019
313
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.23 KB | None | 0 0
  1. #include <bits/stdc++.h>
  2. #include <ext/pb_ds/assoc_container.hpp>
  3. #include <ext/pb_ds/priority_queue.hpp>
  4.  
  5. using namespace std;
  6. using namespace __gnu_pbds;
  7.  
  8. typedef __gnu_pbds::priority_queue<int, less<int>, pairing_heap_tag> heap;
  9.  
  10. int main()
  11. {
  12.     int arr1[] = {9, 0, 1, 2, 5, 3, 4, 7, 6, 8};
  13.     int arr2[] = {19, 10, 11, 12, 15, 13, 14, 17, 16, 18};
  14.  
  15.     heap pq1, pq2;
  16.  
  17.     //push()
  18.     for(auto it : arr1)
  19.         pq1.push(it);
  20.     for(auto it : arr2)
  21.         pq2.push(it);
  22.  
  23.  
  24.     //top(), pop(), size(), empty()
  25.     printf("pq1: ");
  26.     while(pq1.size())
  27.     {
  28.         printf("%d ", pq1.top());
  29.         pq1.pop();
  30.     }
  31.     puts("");
  32.  
  33.     printf("pq2: ");
  34.     while(!pq2.empty())
  35.     {
  36.         printf("%d ", pq2.top());
  37.         pq2.pop();
  38.     }
  39.     puts("");
  40.  
  41.  
  42.     //push()
  43.     for(auto it : arr1)
  44.         pq1.push(it);
  45.     for(auto it : arr2)
  46.         pq2.push(it);
  47.  
  48.  
  49.     //join()
  50.     pq1.join(pq2);
  51.  
  52.     printf("pq1.join(pq2): ");
  53.     while(pq1.size())
  54.     {
  55.         printf("%d ", pq1.top());
  56.         pq1.pop();
  57.     }
  58.     puts("");
  59.  
  60.     return 0;
  61. }
  62. /**
  63. OUTPUT:
  64. pq1: 9 8 7 6 5 4 3 2 1 0
  65. pq2: 19 18 17 16 15 14 13 12 11 10
  66. pq1.join(pq2): 19 18 17 16 15 14 13 12 11 10 9 8 7 6 5 4 3 2 1 0
  67. **/
Add Comment
Please, Sign In to add comment