Array_ADT/merge_array.cpp
// this function will merge two sorted arrays together
this function will merge two sorted arrays together
this function will merge two sorted arrays together
int merge_arrays(int a[], int n, int b[], int m, int c[])
{
    int i, j, k;
    i=j=k=0;
    while(i<n && j<m)
    {
        if(a[i]<b[j]) 
        {
            c[k]=a[i]; 
            i++; 
            k++; 
        }
        else
        {
            c[k]=b[j]; 
            j++; 
            k++; 
        }
    }
    for(; i<n; i++)
    {
        c[k]=a[i];
        k++;
    }
    for(; j<m; j++)
    {
        c[k]=b[j];
        k++;
    }
    int p=n+m;
    return c[p]; 
}
int merge_arrays ( int a [ ] , int n , int b [ ] , int m , int c [ ] ) { int i , j , k ; i = j = k = 0 ; while ( i < n && j < m ) { if ( a [ i ] < b [ j ] ) { c [ k ] = a [ i ] ; i ++ ; k ++ ; } else { c [ k ] = b [ j ] ; j ++ ; k ++ ; } } for ( ; i < n ; i ++ ) { c [ k ] = a [ i ] ; k ++ ; } for ( ; j < m ; j ++ ) { c [ k ] = b [ j ] ; k ++ ; } int p = n + m ; return c [ p ] ; }
this function will merge two sorted arrays together
this function will merge two sorted arrays together
// if element of a is smaller the element of b // store in c // incremenet index in a[] // increment index in c[] // else store b[] lemeent in c[] // increment index of b[] // increment index of c[] // there might be case where element in any of the array might left // so for that we'll start with present value of i and j and store in c[] // by incrementing it's array index by one // return c[] as result