Загрузка данных


#include <iostream>

// out должен иметь размер n + m
void mergeSorted(const int* a, int n, const int* b, int m, int* out) {
    int i = 0, j = 0, k = 0;
    while (i < n && j < m) {
        if (a[i] <= b[j]) {
            out[k++] = a[i++];
        } else {
            out[k++] = b[j++];
        }
    }
    while (i < n) out[k++] = a[i++];
    while (j < m) out[k++] = b[j++];
}

int main() {
    int a[] = {1, 3, 5, 7};
    int b[] = {2, 4, 6, 8};
    int n = 4, m = 4;

    int result[8];
    mergeSorted(a, n, b, m, result);

    for (int i = 0; i < n + m; ++i) std::cout << result[i] << " ";
    std::cout << std::endl;

    return 0;
}