Skip to content

Instantly share code, notes, and snippets.

@Bekt
Last active December 10, 2015 02:58
Show Gist options
  • Save Bekt/4371148 to your computer and use it in GitHub Desktop.
Save Bekt/4371148 to your computer and use it in GitHub Desktop.
//http://coolcodebro.blogspot.com/2012/12/merge-b-into-a.html
void mergeBintoA(int[] arrayA, int[] arrayB, int lastIndexA) {
int indexA = lastIndexA;
int indexB = arrayB.length-1;
int indexC = arrayA.length-1;
//Merge
while(indexA >= 0 && indexB >= 0)
arrayA[indexC--] = arrayA[indexA] > arrayB[indexB] ? arrayA[indexA--] : arrayB[indexB--];
//Fix the end if necessary
while(indexB >= 0)
arrayA[indexC--] = arrayB[indexB--];
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment