Advertisement
Guest User

Untitled

a guest
Apr 18th, 2015
201
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.57 KB | None | 0 0
  1. public class Solution {
  2. public void merge(int A[], int m, int B[], int n) {
  3. int index = m + n -1;
  4. int a = m - 1;
  5. int b = n - 1;
  6. while(a >= 0 && b >=0){
  7. if(A[a] > B[b]){
  8. A[index] = A[a];
  9. a--;
  10. index--;
  11. }else{
  12. A[index] = B[b];
  13. b--;
  14. index--;
  15. }
  16. }
  17. if(a < 0){
  18. while(index >= 0){
  19. A[index] = B[b];
  20. b--;
  21. index--;
  22. }
  23. }
  24.  
  25. }
  26. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement