A sequence of two ascending (or descending) data sequences is merged into one that is still sorted in the original order.
On the code:
#include <stdio.h> #include <stdlib.h> #define m 6#define n 4int Main () { int a[m]={-3,6,19,26,68,100}, b[ N]={8,10,12,22}; int i,j,k,c[m+n]; int l; i=j=k=0; printf ("element of array A: \ n"); for (l = 0; l < m; l++) { printf ("%d ", A[l]);} printf ("Elements of the \NB array: \ n"); for (l = 0; l < n; l++) { printf ("%d ", B[l]);} printf ("\ n" of the merged array element: \ n "), while (i<m && j<n)/ * Stores the smaller number in a, B array sequentially in the C array */ {if (A[i]<b[j]) {c[k ]=a[i]; i++;} else {c[k]=b[j]; j + +;} k++; }while (i>=m && j<n)/ * If all the data in a is complete, store all the remaining number B in C */{c[k]=b[j]; k++; j + +;} while (J>=n && I<M) /* If all the data in B is complete, store the remaining number of a in C */{ c[k]=a[i]; k++; i++;} for (i=0;i<m+n;i++) printf ("%d ", C[i]); return 0;}
Execution Result:
Merging and sorting of C language