/* in this implemenation, we assume the followings: 1. the user is going to enter numbers one by one, separted by a signle space. When the first array is done, an ENTER ('\n') will be used as input and the second array will start. 2. each array input will not have more than 10 integers Gang Qu */ #include void sort(int [], int, int, int [], int, int); int main() { int A[10], B[10], cnt_a, cnt_b; int i, j; char ch; printf("Enter the first array:"); i = 0; do { scanf("%d%c", &A[i], &ch); // read in an integer that next character ch // use the value of ch to check whether there is more numbers ( ) // or the first array has reached the end (\n) i++; } while (ch==' ' && i<10); cnt_a = i; printf("Enter the second array:"); i = 0; do { scanf("%d%c", &B[i], &ch); i++; } while (ch==' ' && i<10); cnt_b = i; sort(A, 0, cnt_a-1, B, 0, cnt_b-1); printf("\n"); return 0; } void sort (int A[], int a, int b, int B[], int c, int d) { if (a <= b && c <= d) { if (A[a] < B[d]) { printf("%d ", A[a]); sort (A, a+1, b, B, c, d); } else { printf("%d ", B[d]); sort(A, a, b, B, c, d-1); } } else { if (a <= b && c > d) { printf("%d ", A[a]); if (a < b) sort (A, a, b-1, B, c, d); } else { if (a > b && c <= d) { printf("%d ", B[d]); if (c < d) sort(A, a, b, B, c, d-1); } } } }