merge two sorted array
//put all elements into array A[]
//read the elements from back m+n
public class Solution {
public void merge(int A[], int m, int B[], int n) {
if(n == 0)
return;
int ptrA = m-1;
int ptrB = n-1;
int ptr = m+n-1;
while(ptrA>=0 && ptrB>=0){
if(A[ptrA] >= B[ptrB]){
A[ptr] = A[ptrA];
ptrA--;
}else{
A[ptr] = B[ptrB];
ptrB--;
}
ptr--;
}
//if there are still elements in arrayB, move them into arrayA
//else return
if(ptrB != -1){
while(ptrB >= 0){
A[ptr] = B[ptrB];
ptr--;
ptrB--;
}
}
}
}