The merge() function is used for merging two halves. The merge(arr, l, m, r) is key process that assumes that arr[l..m] and arr[m+1..r] are sorted and merges the two sorted sub-arrays into one.
- Parameters
-
| arr | - array with two halves arr[l...m] and arr[m+1...l] |
| l | - left index or start index of first half array |
| m | - right index or end index of first half array |
(The second array starts form m+1 and goes till l)
- Parameters
-
| l | - end index or right index of second half array |
38 int *L =
new int[n1], *R =
new int[n2];
40 for (i = 0; i < n1; i++) L[i] = arr[l + i];
41 for (j = 0; j < n2; j++) R[j] = arr[m + 1 + j];
46 while (i < n1 && j < n2) {