A few days ago in busy other things, no time to update, today updated a few, although there are several SMR blog temporarily not open, has been written well, will slowly open later
Update an algorithmic question about sorting today
1 Merge Sorted Array
Describe
Given sorted integer arrays A and B, merge B into a as one sorted array.
Note:you may assume a have enough space to hold additional elements from B. The number ofelements initialized in A D B is M and N respectively.
1#include <stdio.h>2 3 4 voidMergetwosort (intA[],intMintB[],intN)5 {6 intlen1=m-1;7 intlen2=n-1;8 intlen3=m+n-1;9 while(len1>=0&&len2>=0)Ten { OneA[LEN3--]=A[LEN1]>B[LEN2]? a[len1--]:b[len2--]; A } - while(len2>=0) - { thea[len3--]=b[len2--]; - } - } - + intMain () - { + inta[4]={1,2,4,9}; A intb[7]={1,3,4,5,7,8,9}; atMergetwosort (A,4B7); - for(inti =0; I < One; i++) - { -printf"%d", A[i]); - } - return 0; in}
Algorithm 5--sort--merge Sorted Array