fork download
  1. #include <algorithm>
  2. #include <vector>
  3.  
  4. namespace model {
  5.  
  6. struct GasStation
  7. {
  8. double getprice(int kindOfGas) const
  9. {
  10. return kindOfGas;
  11. }
  12. };
  13.  
  14. struct StationVector
  15. {
  16. std::vector<GasStation> localStations;
  17.  
  18. struct SortByGrade
  19. {
  20. int kindOfGas_;
  21. SortByGrade(int kindOfGas)
  22. :kindOfGas_(kindOfGas)
  23. {
  24. }
  25.  
  26. bool operator() (GasStation const &L, GasStation const & R) const
  27. {
  28. // You'll need other comparisons here, but this is a good start...
  29. return L.getprice(kindOfGas_) < R.getprice(kindOfGas_);
  30. }
  31. };
  32.  
  33. void sortByGrade(int kindOfGas)
  34. {
  35. std::sort(localStations.begin(), localStations.end(), SortByGrade(kindOfGas));
  36. }
  37. };
  38.  
  39. }
  40.  
  41. int main()
  42. {
  43. model::StationVector sv;
  44. sv.sortByGrade(0);
  45. }
  46.  
Success #stdin #stdout 0s 2848KB
stdin
Standard input is empty
stdout
Standard output is empty