fork download
  1. #include <vector>
  2.  
  3. #include <iostream>
  4.  
  5. #include <algorithm>
  6.  
  7. using namespace std;
  8.  
  9. class Pocket
  10. {
  11.  
  12. int value;
  13.  
  14. public:
  15.  
  16. Pocket (int value):value (value)
  17. {
  18. }
  19.  
  20. int getValue () const
  21. {
  22. return value;
  23. }
  24.  
  25. bool operator < (const Pocket & _Right) const
  26. {
  27. return value < _Right.value;
  28. }
  29.  
  30. };
  31.  
  32. ostream & operator << (ostream & stream, const Pocket & pocket)
  33. {
  34.  
  35. stream << pocket.getValue ();
  36.  
  37. return stream;
  38.  
  39. }
  40. void
  41. printer (Pocket i)
  42. {
  43.  
  44. cout << i << ", ";
  45.  
  46. }
  47.  
  48. int
  49. main ()
  50. {
  51.  
  52. int mynumbers1[] = { 8, 9, 7, 6 };
  53.  
  54. int mynumbers2[] = { 4, 1, 4, 5 };
  55.  
  56. vector < Pocket > v1 (7, 0);
  57.  
  58. sort (mynumbers2, mynumbers2 + 4);
  59.  
  60. copy (mynumbers1, mynumbers1 + 3, v1.begin ());
  61.  
  62. copy (mynumbers2, mynumbers2 + 3, v1.begin () + 3);
  63.  
  64. sort (mynumbers1, mynumbers1 + 4); //LINE I
  65.  
  66. inplace_merge (v1.begin (), v1.begin () + 4, v1.end ()); //LINE II
  67.  
  68. for_each (v1.begin (), v1.end (), printer);
  69.  
  70. return 0;
  71. }
  72.  
Success #stdin #stdout 0s 5284KB
stdin
Standard input is empty
stdout
4, 4, 0, 8, 9, 7, 1,