Skip to content

Instantly share code, notes, and snippets.

@kobeumut
Created December 8, 2019 19:58
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save kobeumut/5af4e9c76f09ca843973f845c4738a73 to your computer and use it in GitHub Desktop.
Save kobeumut/5af4e9c76f09ca843973f845c4738a73 to your computer and use it in GitHub Desktop.
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