別の方法
#include <stdio.h>
#include <stdlib.h>
int* merge(int* array1, int* array2){
int *result = NULL;
int size=0;
result = (int*)malloc(sizeof(int)*48);//need capacity check!
while(*array1 || *array2){
if(*array1 && *array2){
if(*array1 < *array2){
result[size++]=*array1++;
continue;
}
if(*array1 > *array2){
result[size++]=*array2++;
continue;
}
if(*array1 == *array2){
result[size++]=*array1++;
array2++;
continue;
}
}
if(*array1){
while(*array1)
result[size++]=*array1++;
}
if(*array2){
while(*array2)
result[size++]=*array2++;
}
}
result[size++]=0;
result = realloc(result, sizeof(int)*size);
return result;
}
int main() {
int subtable1[] = {15, 20, 40, 69, 74, 83, 0};
int subtable2[] = {12, 40, 58, 74, 82, 94, 111, 0};
int subtable3[] = {19, 30, 69, 0};
int subtable4[] = {12, 19, 0};
int subtable5[] = {44, 64, 74, 83, 0};
// int *table[] = { subtable1, subtable2, subtable3, subtable4, subtable5 };
int *m12, *m34, *m1234, *result;
int counter=0;
m12=merge(subtable1, subtable2);
m34=merge(subtable3, subtable4);
m1234=merge(m12, m34);
result=merge(m1234, subtable5);
//check print
for(counter=0;result[counter];++counter)
printf("%d ", result[counter]);
printf("\n");
//need free
return 0;
}