Question: A [] and B [] are arrays in an ordered order. Merge A [] and B [] into C []. For example: A [] = {,}; B [] = {,}, we need to get C [] =, 8, 10, 15, 20 }.
Solution: 1) compare a [0] and B [0] first. If a [0] is relatively small, assign the value of a [0] to C [0]. then compare a [1] and B [0]. 2) When all the values in a number of groups have been assigned to C [], the remaining elements of the other array are directly assigned to C [] at a time.
The following is implemented in Java.
Public class test {public static void main (string [] ARGs) {int [] A = {10, 20, 50, 70, 80,500,100 1}; int [] B = {10, 40, 60, 90, 100,120,200}; int alength =. length; int blength = B. length; int [] C = new int [alength + blength]; int aindex = 0; int bindex = 0; For (INT I = 0; I <alength + blength; I ++) {if (a [aindex] <= B [bindex]) {C [I] = A [aindex]; If (aindex <alength-1) {aindex ++;} // else {for (int t = I + 1; t <alength + blength; t ++) When all data in array A has been read) {c [T] = B [bindex]; bindex ++;} break ;}} else {C [I] = B [bindex]; If (bindex <blength-1) {bindex ++;} // when all data in array B has been read, else {for (int t = I + 1; t <alength + blength; t ++) {c [T] = A [aindex]; aindex ++;} break ;}}for (INT I = 0; I <alength + blength; I ++) {system. out. println (C [I]) ;}}