fork download
  1. #include<bits/stdc++.h>
  2. using namespace std;
  3. #define ll long long
  4. #define endl '\n'
  5. #define sz(v) (int)v.size()
  6. #define all(v) v.begin(), v.end()
  7. void dbg_out() { cerr << "\b\b]\n"; }
  8. template<typename Head, typename... Tail> void dbg_out(Head H, Tail... T){ cerr << H << ", "; dbg_out(T...);}
  9. #define watch(...) cerr << "[" << #__VA_ARGS__ << "]: [", dbg_out(__VA_ARGS__)
  10.  
  11.  
  12. /****************************** CODE IS HERE ***********************************/
  13.  
  14. struct cmp {
  15. bool operator()(int a, int b){
  16. return a > b;
  17. }
  18. };
  19.  
  20. struct my{
  21. struct comparator{
  22. bool operator()(int a, int b){
  23. return (a > b);
  24. }
  25. };
  26.  
  27. bool (*f)(int,int) = [](int a, int b){ return (a < b);}; //I guess, auto does not support in class as return type
  28.  
  29. void go(){
  30. vector <int> v = {4, 3, 2, 10, 1, -1, 0, 20};
  31. sort(all(v), comparator());
  32. for (int i: v)
  33. cout << i << ' ';
  34. cout << endl;
  35.  
  36. sort(all(v), f);
  37. for(int i: v)
  38. cout << i << ' ';
  39. cout << endl;
  40. }
  41.  
  42. }OBJ;
  43.  
  44. int main(){
  45. ios_base::sync_with_stdio(false); cin.tie(nullptr);
  46. priority_queue<int, vector<int>, cmp> pq;
  47. pq.push(20);
  48. pq.push(10);
  49. pq.push(30);
  50. pq.push(40);
  51. pq.push(0);
  52. while(!pq.empty()){
  53. cout << pq.top() << ' ';
  54. pq.pop();
  55. }
  56. cout << endl;
  57. OBJ.go();
  58. return 0;
  59. }
  60.  
Success #stdin #stdout 0s 4484KB
stdin
Standard input is empty
stdout
0 10 20 30 40 
20 10 4 3 2 1 0 -1 
-1 0 1 2 3 4 10 20