[题目分析]数组A和B的元素分别有序欲将两数组合并到C数组使C仍有序应将A和B拷贝到C只要注意A和B数组指针的使用以及正确处理一数组读完数据后将另一数组余下元素复制到C中即可
void union(int A[]B[]C[]mn)
//整型数组A和B各有m和n个元素前者递增有序后者递减有序本算法将A和B归并为递增有序的数组C
{i=; j=n; k=;// ijk分别是数组AB和C的下标因用C描述下标从开始
while(i<m && j>=)
if(a[i]<b[j]) c[k++]=a[i++] else c[k++]=b[j];
while(i<m) c[k++]=a[i++];
while(j>=) c[k++]=b[j];
}算法结束
[算法讨论]若不允许另辟空间而是利用A数组(空间足够大)则初始k=m+n请参见第章算法设计第题
[] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] []