C++ 算法题:题库插入排序
#include
int main() {
int n, m;
cin >> n >> m;
vector
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;
}
原文地址: https://www.cveoy.top/t/topic/qmlT 著作权归作者所有。请勿转载和采集!