fork(3) download
  1. #include <iostream>
  2. #include <vector>
  3. #include <algorithm>
  4. using namespace std;
  5.  
  6.  
  7. struct Mop{
  8. Mop( string n, int a){
  9. name = n;
  10. age = a;
  11. }
  12. string name;
  13. int age;
  14. bool operator < ( const Mop&a) const {
  15. return age < a.age;
  16. }
  17. };
  18.  
  19.  
  20. void AddVector(vector<Mop> &a, string n , int aa){
  21. Mop mop(n,aa);
  22. auto it = lower_bound(a.begin(), a.end(), mop , [](const Mop &ar, const Mop &br){ return ar < br;});
  23. a.insert(it, mop);
  24. }
  25. int main()
  26. {
  27. vector<Mop> a;
  28. AddVector(a,"John",15);
  29. AddVector(a,"Swan",10);
  30. return 0;
  31. }
Success #stdin #stdout 0s 3456KB
stdin
Standard input is empty
stdout
Standard output is empty