Advertisement
Guest User

Untitled

a guest
Nov 9th, 2019
81
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.63 KB | None | 0 0
  1. #include <iostream>
  2. #include <queue>
  3. #include <vector>
  4. using namespace std;
  5. class Elem{
  6. public:
  7. int x;
  8. bool operator()(const Elem & el ) const{
  9. return x < el.x;
  10. }
  11. };
  12.  
  13.  
  14. /*typedef struct{
  15. int x;
  16.  
  17. }Elem;
  18. */
  19.  
  20. bool operator()(Elem a, Elem b)
  21. {
  22. return a.x < b.x;
  23. }
  24.  
  25.  
  26. int main()
  27. {
  28. vector<int> v;
  29. priority_queue <Elem, cmp> q;
  30. Elem e;
  31. int i, n, y;
  32. cin >> n;
  33. for(i = 1; i <= n; ++i)
  34. {
  35. cin >> y;
  36. e.x = y;
  37. q.push(e);
  38. }
  39. for(i = 1; i <= n; ++i)
  40. {
  41. e = q.top();
  42. v.push_back(e.x);
  43. q.pop();
  44. }
  45. for(i = 1; i <= n; ++i)
  46. cout << v[i]<<" ";
  47. return 0;
  48. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement