#include #include using namespace std;

int main() { int n, m; cin >> n >> m; vector t(n); vector d(m); for (int i = 0; i < n; i++) { cin >> t[i]; } for (int i = 0; i < m; i++) { cin >> d[i]; }

vector<int> result;
int tIndex = 0;
int dIndex = 0;
while (tIndex < n && dIndex < m) {
    if (t[tIndex] <= d[dIndex]) {
        result.push_back(t[tIndex]);
        tIndex++;
    } else {
        result.push_back(d[dIndex]);
        dIndex++;
    }
}

while (tIndex < n) {
    result.push_back(t[tIndex]);
    tIndex++;
}

while (dIndex < m) {
    result.push_back(d[dIndex]);
    dIndex++;
}

for (int i = 0; i < result.size(); i++) {
    cout << result[i] << " ";
}

return 0;

}

C++ 算法题:题库插入排序

原文地址: https://www.cveoy.top/t/topic/qmlT 著作权归作者所有。请勿转载和采集!

免费AI点我,无需注册和登录