``````#include<iostream>
#include<vector>
using namespace std;

double FindMedium(vector<double>& nums1, vector<double>& nums2) {

vector<double> nums3;
int a = nums1.size();
int b = nums2.size();
int i = 0, j = 0, k = 0;
double medium;
if (a == 0) {
for (j = 0; j <= b; j++) {
nums3[k] = nums2[j];
k++;
}
}
else if (b == 0) {
for (i = 0; i <= b; i++) {
nums3[k] = nums1[i];
k++;
}
}
else if (a == 0 && b == 0) {
cout << "两个数组均为空";
}
else {
while (i < a && j < b) {
if (nums1[i] < nums2[j]) {
nums3[k] = nums1[i];
i++; k++;
}
else {
nums3[k] = nums2[j];
k++; j++;
}
}
}
int c = nums3.size();
if (c % 2 == 0) {
medium = (nums3[c / 2 - 1] + nums3[c / 2]) / 2;
}
else {
medium = nums3[(c - 1) / 2];
}
return medium;
}
int main() {
vector<double> na, nb, nc;
int a, b;
double med;
cout << "请有序输入第一个数组的长度";
cin >> a;
cout << "请输入a数组的元素";
for (int i = 0; i <= a; i++) {
cin >> na[i];
}
cout << "请有序输入第二个数组的长度";
cin >> b;
cout << "请输入b数组的元素";
for (int j = 0; j <= b; j++) {
cin >> nb[j];
}
med = FindMedium(na, nb);
cout << "两数组的中位数是" << med;
return 0;
}
``````