2Z_2DZ

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
int* mergerArr(int* arr1, int* arr2, int n1, int n2){
int* arr = (int*)malloc((n1+n2)*sizeof(int));
int n = (n1+n2);
int count1=0, count2=0;
for(int i=0; i<n; i++){
if(count1==n1){
for(int j=i; j<n; j++) { arr[j] = arr2[count2++]; }
break;
}
if(count2==n2){
for(int j=i; j<n; j++) { arr[j] = arr1[count1++]; }
break;
}
if(arr1[count1]<arr2[count2]){
arr[i] = arr1[count1++];
} else {
arr[i] = arr2[count2++];
}
}
return arr;
}