public static void merge(int[] result, int[] left, int[] right) {
                int i1 = 0;   // index into left array
                int i2 = 0;   // index into right array

                for (int i = 0; i < result.length; i++) {
                        if (i2 >= right.length || (i1 < left.length &&
                                        left[i1] <= right[i2])) {
                                result[i] = left[i1];    // take from left
                                i1++;
                        } else {
                                result[i] = right[i2];   // take from right
                                i2++;
                        }
                }
        }