#include <iostream>
#include <stdlib.h>
#include <algorithm>
using namespace std;
int main() {
int m = 0, n = 0;
int *a = nullptr;
int *b = nullptr;
int *c = nullptr;
while (cin >> m)
{
a = (int *)malloc(sizeof(int)*m);
for (int i = 0;i < m;i++) {
cin >> a[i];
}
sort(a, a + m);
cin >> n;
b = (int *)malloc(sizeof(int)*n);
for (int i = 0;i < n;i++) {
cin >> b[i];
}
sort(b, b + n);
c = (int *)malloc(sizeof(int)*(m + n));
int ai = 0, bj = 0;
int k = 0;
while (ai < m && bj < n) {
int temp = 0;
if (a[ai] <= b[bj]) {
temp = a[ai];
c[k++] = a[ai++];
}
else {
temp = b[bj];
c[k++] = b[bj++];
}
}
while (ai < m) c[k++] = a[ai++];
while (bj < n) c[k++] = b[bj++];
for (int i = 0;i < k;i++)
cout << c[i] << " ";
if (k == 0)
cout << endl;
}
//system("pause");
return 0;
}
有序线性表的有序合并(基于顺序表,链表写的有点多,繁琐)
最新推荐文章于 2022-11-19 16:27:01 发布