Created
December 8, 2019 19:58
-
-
Save kobeumut/5af4e9c76f09ca843973f845c4738a73 to your computer and use it in GitHub Desktop.
This file contains 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
fun alternateMerge(arr1: IntArray, arr2: IntArray, | |
n1: Int, n2: Int, arr3: IntArray) { | |
var i = 0 | |
var j = 0 | |
var k = 0 | |
// Traverse both array | |
while (i < n1 && j < n2) { | |
arr3[k++] = arr1[i++] | |
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