Page 518 - Cs_withBlue_J_C11_Flipbook
P. 518
8 int n1 = m - l + 1;
9 int n2 = r - m;
10 int L[] = new int [n1];
11 int R[] = new int [n2];
12 //dividing and copying the data into temp arrays
13 for (int i=0; i<n1; ++i)
14 {
15 L[i] = arr[l + i];
16 }
17 for (int j=0; j<n2; ++j)
18 {
19 R[j] = arr[m + 1+ j];
20 }
21 // Initial indexes of first and second subarrays
22 int i = 0, j = 0;
23 // Initial index of merged subarry array
24 int k = l;
25 while (i < n1 && j < n2)
26 {
27 if (L[i] <= R[j])
28 {
29 arr[k] = L[i];
30 i++;
31 }
32 else
33 {
34 arr[k] = R[j];
35 j++;
36 }
37 k++;
38 }
39 /* Copy remaining elements of L[] if any */
40 while (i < n1)
41 {
516516 Touchpad Computer Science-XI

