task2.cpp 665 B

123456789101112131415161718192021222324252627282930313233343536
  1. #include <iostream>
  2. #include <vector>
  3. int main() {
  4. std::vector<int> arr1 = {1, 3, 5};
  5. std::vector<int> arr2 = {2, 4, 6};
  6. std::vector<int> merged;
  7. int i = 0, j = 0;
  8. while (i < arr1.size() && j < arr2.size()) {
  9. if (arr1[i] < arr2[j]) {
  10. merged.push_back(arr1[i]);
  11. i++;
  12. } else {
  13. merged.push_back(arr2[j]);
  14. j++;
  15. }
  16. }
  17. while (i < arr1.size()) {
  18. merged.push_back(arr1[i]);
  19. i++;
  20. }
  21. while (j < arr2.size()) {
  22. merged.push_back(arr2[j]);
  23. j++;
  24. }
  25. for (int num : merged) {
  26. std::cout << num << " ";
  27. }
  28. return 0;
  29. }