Current location - Plastic Surgery and Aesthetics Network - Plastic surgery and beauty - How to combine two ordered arrays A and B into an array C by programming in C language?
How to combine two ordered arrays A and B into an array C by programming in C language?
Take your example to write, and you can modify it more generally.

The core code of this algorithm is:

int I = j = k = 0;

//loop comparison, insert the small one into the c array.

While (I<3 & amp& ampj & lt3) {

if(a[I]& lt; b[j])c[k++]= a[i++];

else c[k++]= b[j++];

}

//Process one of the arrays.

While (I<3) c [k++] = a [I++];

while(j & lt; 3)c[k++]= b[j++];

Maybe there is a better realization, think for yourself!