以归并的思想解决两数组合并问题:
//use MergeSort
#include <iostream>
#include <vector>
using namespace std;
template <typename T>
void mergeSort(vector<T> &a,vector<T> first,int firstNum,vector<T> second,int secondNum)
{
int i=0,j=0,z=0;
while(i < firstNum && j < secondNum )
{
if(first[i] < second[j])
a[z++] = first[i++];
else
a[z++] = second[j++];
}
while(i < firstNum)
a[z++] = first[i++];
while(j < secondNum)
a[z++] = second[j++];
}
int main()
{
int A1[4] = {
2,5,7,9};
int A2[6] = {
1,3,4,6,8,10};
vector<int> firstA(A1,A1+4);
vector<int> secondA(A2,A2+6);
<