Advertisement
Guest User

Untitled

a guest
Sep 12th, 2018
101
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.65 KB | None | 0 0
  1. #ifndef CPP_ADVANCED_ORDEREDINSERTER_H
  2. #define CPP_ADVANCED_ORDEREDINSERTER_H
  3.  
  4. #include <vector>
  5. #include "Company.h"
  6.  
  7. class OrderedInserter {
  8.   std::vector<const Company*>& companies;
  9. public:
  10.   explicit OrderedInserter(std::vector<const Company*>& companies) :
  11.       companies(companies)
  12.   { }
  13.  
  14.   void insert(const Company* company)
  15.   {
  16.     auto it = this->companies.begin();
  17.     while (it != this->companies.end()) {
  18.       if ((*it)->getId() > company->getId()) {
  19.         this->companies.insert(it, company);
  20.         return;
  21.       }
  22.       ++it;
  23.     }
  24.     this->companies.push_back(company);
  25.   }
  26. };
  27.  
  28. #endif //CPP_ADVANCED_ORDEREDINSERTER_H
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement