Skip to content

Instantly share code, notes, and snippets.

@rohith2506
Created March 3, 2015 06:52
Show Gist options
  • Save rohith2506/212b86a2013cde0f4ae5 to your computer and use it in GitHub Desktop.
Save rohith2506/212b86a2013cde0f4ae5 to your computer and use it in GitHub Desktop.
Merge two sorted arrays
// Merge two sorted arrays
// http://www.geeksforgeeks.org/merge-one-array-of-size-n-into-another-one-of-size-mn/
// Time complexity: 0(m+n)
void merge(A, B){
int k=0;
for(int i=m; i<m+n; i++)A[i] = B[k];
k=0;
i=0;j=m;
while(k < (m+n)){
if(A[i] > B[j]){
A[k] = A[i];
i++;
k++;
}
else {
A[k] = B[j];
k++;
j++;
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment