#include<stdio.h>
int main(){
int n;
cin>>n;
for(int i=1;i<=n;i++)cin>>a[i];
for(int i=1;i<=n;i++)cin>>b[i];
int x=1,y=1,tot=0;
while(x<=n&&y<=n){
if(a[x]<b[y]){
ans[++tot]=a[x];
x++;
}else{
ans[++tot]=b[y];
y++;
}
}
while(x<=n){
ans[++tot]=a[x];
x++;
}
while(y<=n){
ans[++tot]=b[y];
x++;
}
return 0;
}
PS:常规方法是冒泡排序 然而时间复杂度为N^2显然不符合要求
原文:https://www.cnblogs.com/AhPuch/p/14820419.html