```
public void merge(int A[], int m, int B[], int n) {
int resultIndex = 0;
int aIndex = m - 1;
int bIndex = n - 1;
for(resultIndex = m + n - 1 ; resultIndex >= 0 ; resultIndex--){
if(bIndex < 0){
//Sorting complete. remaining numbers in A are already sorted
break;
}
if(aIndex >= 0 && A[aIndex] >= B[bIndex]){
A[resultIndex] = A[aIndex];
aIndex--;
}else{
A[resultIndex] = B[bIndex];
bIndex--;
}
}
}
```