Here you can find the source of merge(double[] a, int[] b, int p, int q, int r)
protected static final void merge(double[] a, int[] b, int p, int q, int r)
//package com.java2s; public class Main { protected static final void merge(double[] a, int[] b, int p, int q, int r) { double[] t = new double[r - p + 1]; int[] v = new int[r - p + 1]; int i, p1 = p, p2 = q + 1; for (i = 0; p1 <= q && p2 <= r; ++i) { if (a[p1] < a[p2]) { v[i] = b[p1];//from w w w . j a v a 2 s .co m t[i] = a[p1++]; } else { v[i] = b[p2]; t[i] = a[p2++]; } } for (; p1 <= q; ++p1, ++i) { v[i] = b[p1]; t[i] = a[p1]; } for (; p2 <= r; ++p2, ++i) { v[i] = b[p2]; t[i] = a[p2]; } for (i = 0, p1 = p; i < t.length; ++i, ++p1) { b[p1] = v[i]; a[p1] = t[i]; } } protected static final void merge(long[] a, int[] b, int p, int q, int r) { long[] t = new long[r - p + 1]; int[] v = new int[r - p + 1]; int i, p1 = p, p2 = q + 1; for (i = 0; p1 <= q && p2 <= r; ++i) { if (a[p1] < a[p2]) { v[i] = b[p1]; t[i] = a[p1++]; } else { v[i] = b[p2]; t[i] = a[p2++]; } } for (; p1 <= q; ++p1, ++i) { v[i] = b[p1]; t[i] = a[p1]; } for (; p2 <= r; ++p2, ++i) { v[i] = b[p2]; t[i] = a[p2]; } for (i = 0, p1 = p; i < t.length; ++i, ++p1) { b[p1] = v[i]; a[p1] = t[i]; } } protected static final void merge(int[] a, int[] b, int p, int q, int r) { int[] t = new int[r - p + 1]; int[] v = new int[r - p + 1]; int i, p1 = p, p2 = q + 1; for (i = 0; p1 <= q && p2 <= r; ++i) { if (a[p1] < a[p2]) { v[i] = b[p1]; t[i] = a[p1++]; } else { v[i] = b[p2]; t[i] = a[p2++]; } } for (; p1 <= q; ++p1, ++i) { v[i] = b[p1]; t[i] = a[p1]; } for (; p2 <= r; ++p2, ++i) { v[i] = b[p2]; t[i] = a[p2]; } for (i = 0, p1 = p; i < t.length; ++i, ++p1) { b[p1] = v[i]; a[p1] = t[i]; } } }