void mergeArrays(int arr1[], int arr2[], int n1,int n2, int arr3[]){
        int i = 0, j = 0, k = 0;
        while (i<n1 && j <n2){
          if (arr1[i] < arr2[j])
            arr3[k++] = arr1[i++];
            arr3[k++] = arr2[j++];
        while (i < n1)
          arr3[k++] = arr1[i++];
        while (j < n2)
          arr3[k++] = arr2[j++];

      Cpp language logo
      Merge two sorted arrays

      Cpp recipes

      The code merges two sorted arrays, arr1 and arr2. The arrays have the same size, n1 and n2. The code starts by sorting arr1 using the natural ordering (the default compared to the compressing order). It then iterates through arr2 and attaches the values from arr1 to the appropriate locations in arr3.


        Add Comment

        Log in to add a comment

        Codiga - All rights reserved 2022.