归并两个有序数组的模板

#include<bits/stdc++.h>
using namespace std;
vector<int> A,B,C;

void merge(){
	int i=0,j=0,k=0;
	C.clear();
	while(i<A.size() || j<B.size()){
		if(i==A.size()&&j<B.size()){
			C.push_back(B[j]);
			j++;
		}
		else if(i<A.size() && j==B.size()){
			C.push_back(A[i]);
			i++;
		} else if(A[i]<=B[j]) {
			C.push_back(A[i]);
			i++;
		}
		else{
			C.push_back(B[j]);
			j++;
		} 
	}
}

int main(){
	int num;
	while(1){
		scanf("%d",&num);
		if(num==-1) break;
		A.push_back(num);
	}
	while(1){
		scanf("%d",&num);
		if(num==-1) break;
		B.push_back(num);
	}
	if(A.size()==0&&B.size()==0) {
		printf("NULL");
		return 0;
	}
	merge();
	for(int i=0;i<C.size();i++){
		printf(i==0?"%d":" %d",C[i]);
	}
	return 0;
}