Java Array Sort sortedMerge(int[] aIds, double[] aVals, int[] bIds, double[] bVals, int[] resIds, double[] resVals)

Here you can find the source of sortedMerge(int[] aIds, double[] aVals, int[] bIds, double[] bVals, int[] resIds, double[] resVals)

Description

sorted Merge

License

Apache License

Declaration

public static void sortedMerge(int[] aIds, double[] aVals, int[] bIds,
            double[] bVals, int[] resIds, double[] resVals) 

Method Source Code

//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;
    }
}

Related

  1. sortedArraysEqual(Object[] arr1, Object[] arr2)
  2. sortedCopyOf(final int[] array)
  3. sortedIndex(double[] values)
  4. sortedIndexOf(Comparable[] list, Comparable val, int lower, int higher)
  5. sortedMerge(int[] a, int[] b)
  6. sortedPointersInto(double d[])
  7. sortedPointersInto_tryingToImproveSpeed(final double d[])
  8. sortedPointersInto_usingStrictfp(final double d[])
  9. sortEigenValues(int n, double[] d, double[][] v)