Open harshanu11 opened 2 years ago
Check this one
void mergeArrays_1(int arr1[], int arr2[], int n1, int n2 ){
int i =0, j=0;
while (i < n1 && j < n2){
if (arr1[i] < arr2[j])
cout<<arr1[i++]<< " ";
else
cout<<arr2[j++]<<" ";
}
// store remaining elements
while (i < n1)
cout<<arr1[i++]<<" ";
while (j < n2)
cout<<arr2[j++]<< " ";
}
Please refer https://github.com/loveBabbar/CodeHelp-DSA-Busted-Series/blob/main/Lecture020%20ArrayQuestions/mergeSortedArray1.cpp
line no 25 is incorrect //copy kardo second array k remaining element ko while(j<m) { arr2[k++] = arr2[j++]; }
It should be arr3[k++] = arr2[j++];