#include <stdio.h>

/**从小到大排序**/
void sort(int array[],int length)
{
int i,j;
for(i = 0; i<length;i++){
for(j = i;j<length;j++){
if(array[j]<array[i]){
int temp = array[j];
array[j] = array[i];
array[i] = temp;
}
}
}
}

/**显示数组数据**/
void disArray(int array[],int length){
int i;
for(i = 0; i<length; i++){
printf("%4d",array[i]);
}
printf("\n");
}

/**两个有序数组合并**/
void unionArr(int array1[],int length1,int array2[],int length2,int destArray[]){
int i,j=0,k=0,n=0;
for(i = 0; i < length1; i++){
for(j = k; j < length2; j++){
if(array1[i] < array2[j]){
destArray[n++] = array1[i];
break;
} else {
destArray[n++] = array2[j];
k++;
}
}
//第二个源数组全部结束
if(k==length2) break;
}

/**第一个数据源有剩余**/
if (k == length2) {
while(i<length1){
destArray[n++] = array1[i++];
}
} else if(k < length2){
/**第二个数据源有剩余**/
while(k<length2){
destArray[n++] = array2[k++];
}
}

}

int main(void){
int firstArray[] = {10,32,65,32,4,5,78,43,1,34,78,8};
sort(firstArray,12);
disArray(firstArray,12);
int secondArray[] = {5,45,67,98,4,3,67,58,6,12,89,91};
sort(secondArray,12);
disArray(secondArray,12);
int destArray[24];
unionArr(firstArray,12,secondArray,12,destArray);
disArray(destArray,24);
}