fork(4) download
  1. #include <iostream>
  2. #include <set>
  3.  
  4. using namespace std;
  5.  
  6. struct cmp
  7. {
  8. bool operator() (const int &a, const int &b)
  9. {
  10. // returns true if a should go before b
  11. return a > b;
  12. }
  13. };
  14.  
  15. int main()
  16. {
  17. set <int, cmp> s;
  18.  
  19. s.insert(2);
  20. s.insert(20);
  21. s.insert(12);
  22. s.insert(-7);
  23.  
  24. for (int x : s)
  25. cout << x << ' ';
  26.  
  27. return 0;
  28. }
Success #stdin #stdout 0s 15240KB
stdin
Standard input is empty
stdout
20 12 2 -7