123456789101112131415161718192021222324252627282930313233343536 |
- #include <iostream>
- #include <vector>
- int main() {
- std::vector<int> arr1 = {1, 3, 5};
- std::vector<int> arr2 = {2, 4, 6};
- std::vector<int> merged;
- int i = 0, j = 0;
- while (i < arr1.size() && j < arr2.size()) {
- if (arr1[i] < arr2[j]) {
- merged.push_back(arr1[i]);
- i++;
- } else {
- merged.push_back(arr2[j]);
- j++;
- }
- }
- while (i < arr1.size()) {
- merged.push_back(arr1[i]);
- i++;
- }
- while (j < arr2.size()) {
- merged.push_back(arr2[j]);
- j++;
- }
- for (int num : merged) {
- std::cout << num << " ";
- }
- return 0;
- }
|