fork download
  1. #include <iostream>
  2. #include <queue>
  3.  
  4. using namespace std;
  5.  
  6. // Jakas klasa.
  7. class X {
  8. public:
  9.  
  10. int x;
  11.  
  12. X(int x) : x(x) {}
  13. };
  14.  
  15. // Funktor porownujacy.
  16. class XComparator {
  17. public:
  18.  
  19. bool operator()(const X *x1, const X *x2) {
  20. return (x1->x < x2->x);
  21. }
  22. };
  23.  
  24. int main() {
  25.  
  26. // Definicja kolejki z funktorem porownujacym.
  27. priority_queue<X *, vector<X *>, XComparator> test;
  28.  
  29. // Dodanie elementow.
  30. test.push(new X(5));
  31. test.push(new X(10));
  32. test.push(new X(-1));
  33. test.push(new X(7));
  34.  
  35. // Jezeli dziala, powinno byc 10.
  36. cout << test.top()->x;
  37.  
  38. // Zwolnienie pamieci.
  39. while (!test.empty()) {
  40. delete test.top();
  41. test.pop();
  42. }
  43.  
  44. return 0;
  45. }
Success #stdin #stdout 0.01s 2856KB
stdin
Standard input is empty
stdout
10