fork download
  1. #include <algorithm>
  2. #include <iostream>
  3. #include <vector>
  4.  
  5. class Time {
  6. int hour;
  7. int minute;
  8. public:
  9. Time(int h, int m) : hour(h), minute(m) {
  10. }
  11.  
  12. int getHour() const { return hour; }
  13. int getMinute() const { return minute; }
  14. };
  15.  
  16. class Times {
  17. std::vector<Time> t;
  18. static bool lowerThan(const Time& a, const Time& b) { return a.getHour() < b.getHour(); }
  19.  
  20. public:
  21. Times() {
  22. // Test data
  23. t.push_back(Time{10, 10});
  24. t.push_back(Time{9, 20});
  25. t.push_back(Time{8, 30});
  26.  
  27. //std::sort(t.begin(), t.end(), lowerThan);
  28.  
  29. std::sort(t.begin(), t.end(), [] (const Time& a, const Time& b) {
  30. return a.getHour() < b.getHour();
  31. });
  32. }
  33.  
  34. void display() {
  35. for (const auto& x : t) {
  36. std::cout << x.getHour() << ":" << x.getMinute() << '\n';
  37. }
  38. }
  39. };
  40.  
  41. int main() {
  42. Times times;
  43. times.display();
  44. }
  45.  
Success #stdin #stdout 0s 3464KB
stdin
Standard input is empty
stdout
8:30
9:20
10:10