Here you can find the source of sortedMerge(int[] aIds, double[] aVals, int[] bIds, double[] bVals, int[] resIds, double[] resVals)
public static void sortedMerge(int[] aIds, double[] aVals, int[] bIds, double[] bVals, int[] resIds, double[] resVals)
//package com.java2s; //License from project: Apache License public class Main { public static void sortedMerge(int[] aIds, double[] aVals, int[] bIds, double[] bVals, int[] resIds, double[] resVals) { int i = 0, j = 0; for (int k = 0; k < resIds.length; ++k) { if (i == aIds.length) { System.arraycopy(bIds, j, resIds, k, resIds.length - k); System.arraycopy(bVals, j, resVals, k, resVals.length - k); j = bIds.length;/* ww w .j av a2 s. co m*/ break; } if (j == bIds.length) { System.arraycopy(aIds, i, resIds, k, resIds.length - k); System.arraycopy(aVals, i, resVals, k, resVals.length - k); i = aIds.length; break; } if (aIds[i] > bIds[j]) { resIds[k] = bIds[j]; resVals[k] = bVals[j]; ++j; } else { resIds[k] = aIds[i]; resVals[k] = aVals[i]; ++i; } } assert i == aIds.length && j == bIds.length; } }