Here you can find the source of mergeAndOrderArray(int[] arrA, int[] arrB)
Parameter | Description |
---|---|
arrA | a parameter |
arrB | a parameter |
public static int[] mergeAndOrderArray(int[] arrA, int[] arrB)
//package com.java2s; //License from project: Open Source License public class Main { /**//from w w w . j av a 2 s . c o m * * @param arrA * @param arrB * @return */ public static int[] mergeAndOrderArray(int[] arrA, int[] arrB) { int[] arr = new int[arrA.length + arrB.length]; int a = 0; int b = 0; for (int i = 0; i < arr.length; i++) { if (a == arrA.length) { arr[i] = arrB[b]; b++; } else if (b == arrB.length) { arr[i] = arrA[a]; a++; } else if (arrA[a] < arrB[b]) { arr[i] = arrA[a]; a++; } else { arr[i] = arrB[b]; b++; } } return arr; } }