SHARE
TWEET

Untitled

a guest Nov 9th, 2019 61 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  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. }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top