Created
November 6, 2019 11:21
-
-
Save LaBlazer/40b21f36261dda34f6d945607d3632f6 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
template<typename T> | |
void mergeArrays(T arr1[], T arr2[], int n1, | |
int n2, T arr3[]) | |
{ | |
int i = 0, j = 0, k = 0; | |
// Traverse both array | |
while (i<n1 && j <n2) | |
{ | |
if (arr1[i] < arr2[j]) | |
arr3[k++] = arr1[i++]; | |
else | |
arr3[k++] = arr2[j++]; | |
} | |
// Store remaining elements of first array | |
while (i < n1) | |
arr3[k++] = arr1[i++]; | |
// Store remaining elements of second array | |
while (j < n2) | |
arr3[k++] = arr2[j++]; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment