我是想将第二个数组的元素加到一个数组里,然后做个排序,但是不知道该如何是实现。
C++版:
其中 sort 表示排序,第一个参数为开始元素,第二个为结束元素,为STL里自带函数
望采纳!
#include <bits/stdc++.h>
using namespace std;
int main()
{
ios::sync_with_stdio(0);
cin.tie(0);
int a,b,m[20001],n[10001];
cin>>a;
for (int i=1;i<=a;i++) cin>>m[i];
cin>>b;
for (int i=1;i<=b;i++) cin>>n[i];
for (int i=1;i<=b;i++) m[a+i]=n[i];
sort(m+1,m+a+b+1);
int t=1;
while (t<=a+b)
{
int x=m[t];
cout<<x<<" ";
while (m[t]==x && t<=a+b) t++;
}
return 0;
}