Java Array Merge merge(int[] a, int[] b)

Here you can find the source of merge(int[] a, int[] b)

Description

merge

License

Open Source License

Declaration

public static int[] merge(int[] a, int[] b) 

Method Source Code

//package com.java2s;
//License from project: Open Source License 

public class Main {

    public static int[] merge(int[] a, int[] b) {
        int[] c = new int[a.length + b.length];
        int p = 0, q = 0;
        while (p < a.length && q < b.length) {
            if (a[p] < b[q])
                c[p + q] = a[p++];/* w ww.  ja v  a  2s  .  c  o m*/
            else
                c[p + q] = b[q++];
        }
        while (p < a.length)
            c[p + q] = a[p++];
        while (q < b.length)
            c[p + q] = b[q++];
        return c;
    }
}

Related

  1. merge(final byte[]... data)
  2. merge(final String[] array1, final String[] array2)
  3. merge(final T[] array1, final T[] array2)
  4. merge(int[] a, int l, int m, int h)
  5. merge(int[] a, int[] b)
  6. merge(int[] a, int[] temp, int fromIndex, int toIndex)
  7. merge(int[] array, int i, int mid, int max)
  8. merge(int[] array1, int[] array2)
  9. merge(int[] x1, int[] x2)