fork download
  1. #include "queue"
  2. #include "vector"
  3. #include "iostream"
  4. #include "functional"
  5. using namespace std;
  6.  
  7.  
  8. struct Compaper_functor{
  9. bool operator()(const int& val1 , const int& val2){
  10. cout <<"val1: "<<val1<<" "<<" val2: "<<val2<<'\n';
  11. return val1 < val2;
  12. }
  13. };
  14.  
  15.  
  16. int main(void){
  17. priority_queue<int , vector<int> , Compaper_functor > pq;
  18. int size;
  19. cin >> size;
  20. while(size--){
  21. int val;
  22. cin >> val;
  23. pq.push(val);
  24. }
  25. while(!pq.empty()){
  26. cout <<'\n'<< pq.top() << '\n';
  27. pq.pop();
  28. }
  29. return 0;
  30. }
Success #stdin #stdout 0s 3476KB
stdin
5
5 4 3 2 1
stdout
val1: 5  val2: 4
val1: 5  val2: 3
val1: 4  val2: 2
val1: 4  val2: 1

5
val1: 3  val2: 4
val1: 2  val2: 1

4
val1: 3  val2: 2
val1: 3  val2: 1

3
val1: 2  val2: 1

2

1