Java Array Merge merge(int[] array, int i, int mid, int max)

Here you can find the source of merge(int[] array, int i, int mid, int max)

Description

merge

License

Open Source License

Declaration

public static void merge(int[] array, int i, int mid, int max) 

Method Source Code

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

public class Main {
    public static void merge(int[] array, int i, int mid, int max) {
        int[] tmp = new int[max - i + 1];
        int k = 0;
        int left = i;
        int right = mid + 1;
        while ((left <= mid) && (right <= max)) {
            if (array[left] <= array[right])
                tmp[k++] = array[left++];
            else/*from  w w w .j a v a2 s .  co m*/
                tmp[k++] = array[right++];
        }
        while (left <= mid) {
            tmp[k++] = array[left++];
        }
        while (right <= max) {
            tmp[k++] = array[right++];
        }
        for (int j = 0; j < tmp.length; j++)
            array[i + j] = tmp[j];
    }
}

Related

  1. merge(final T[] array1, final T[] array2)
  2. merge(int[] a, int l, int m, int h)
  3. merge(int[] a, int[] b)
  4. merge(int[] a, int[] b)
  5. merge(int[] a, int[] temp, int fromIndex, int toIndex)
  6. merge(int[] array1, int[] array2)
  7. merge(int[] x1, int[] x2)
  8. merge(int[]... arrs)
  9. merge(long[] theArray, long[] workSpace, int lowPtr, int highPtr, int upperBound)