Page 589 - ComputerScience_Class_11
P. 589

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              {

                   42                  arr[k] = L[i];
                   43                  i++;

                   44                  k++;

                   45              }
                   46              /* Copy remaining elements of R[] if any */

                   47              while (j < n2)

                   48              {
                   49                  arr[k] = R[j];

                   50                  j++;

                   51                  k++;
                   52              }

                   53          }

                   54          //function to sort the array
                   55

                   56          void sort(int arr[], int l, int r)





                                                                                                Internal Assessment  587
   584   585   586   587   588   589   590   591   592   593   594