// java code for MergeSort // adapted from Gittleman "Programs, Objects, Graphics" public static void mergeSort(int[] x, int left, int right) { if (leftright1) // first array is empty, copy rest of second for( int j=left2; j<=right2; j++) temp[i++] = x[left2++]; else // second array is empty, copy rest of first for( int j=left1; j<=right1; j++) temp[i++] = x[left1++]; System.arraycopy(temp, 0, x, oldPosition, size) } // arraycopy is method of the java.lang.System class // parameters for arraycopy are: // source array // starting index in the source array at which to start copying // destination array // starting index in the destination array for the copied elements // number of elements to copy