Advertisement
Guest User

Untitled

a guest
Jul 19th, 2019
61
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.58 KB | None | 0 0
  1. #include <iostream>
  2. #include <queue>
  3.  
  4. struct datos {
  5. int n, m;
  6. };
  7.  
  8. bool operator<(const datos& a, const datos& b) {
  9. return a.n < b.n; // ordenando por n de menor a mayor, entonces en la cima del montículo estará el elemento con mayor n
  10. }
  11.  
  12. int main( ) {
  13. std::priority_queue<datos> q;
  14. q.push(datos{5, 7});
  15. q.push(datos{2, 10});
  16. q.push(datos{9, 3});
  17. q.push(datos{6, 5});
  18.  
  19. while (!q.empty( )) {
  20. auto actual = q.top( );
  21. std::cout << actual.n << " " << actual.m << "n";
  22. q.pop( );
  23. }
  24. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement