Advertisement
Guest User

Database.cpp

a guest
Dec 16th, 2019
163
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.19 KB | None | 0 0
  1. #include "database.h"
  2.  
  3. using namespace std;
  4.  
  5. void Database::Add(const Date& date, const std::string& event) {
  6.  
  7.     base_vector.push_back(make_pair(date, event));
  8.     stable_sort(base_vector.begin(), base_vector.end(),
  9.         [](const pair<Date, string>& lhs,
  10.             const pair<Date, string>& rhs) {
  11.                 return lhs.first < rhs.first;
  12.         });
  13. }
  14.  
  15. void Database::Print(ostream& is) {
  16.  
  17.  
  18.     Date chek = base_vector.begin()->first;
  19.     for (auto it = base_vector.begin(); it < base_vector.end(); it++) {
  20.         if (it == base_vector.begin()) {
  21.             is << it->first << ' ' << it->second << ' ';
  22.         }
  23.         if (it->first == chek) {
  24.             is << it->second << ' ';
  25.         }
  26.         else if (it->first != chek) {
  27.             is << endl << it->first << ' ' << it->second << ' ';
  28.         }
  29.     }
  30. }
  31. std::string Database::Last(const Date& a) {
  32.     auto r = lower_bound(base_vector.begin(), base_vector.end(), [a](const  pair<Date, std::string>& i) {
  33.         return i.first < a;
  34.         });
  35.     return r->second;
  36. }
  37.  
  38. ostream& operator << (std::ostream& stream, const std::pair<Date, string>& a) {
  39.     stream << a.first << ' ' << a.second;
  40.     return stream;
  41. }
  42. bool operator <(const std::pair<Date, string>& lhs, const std::pair<Date, string>& rhs) {
  43.     return lhs.first < rhs.first;
  44. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement