pset3/find/helpers_merge.c
void merge(int b[], int a[], int l, int m, int r)
{
    
    // index in each array
    int i = l;
    int j = m;
    
    // index in A
    int k = l;
    
    // while there are elements on each side
    while ( i < m || j < r )
    {
        
        // copy element from the left array
        if ( i<m && (b[i] < b[j] || j >= r) )
        {
            a[k] = b[i];
            i++;
        }

        // copy element from the right array
        else
        {
            a[k] = b[j];
            j++;
        }
        k++;
    }
}
/**
 * Merge fucntion for the merge sort
 */
Merge fucntion for the merge sort
Merge fucntion for the merge sort
void merge(int b[], int a[], int l, int m, int r)
{
    int i = l;
    int j = m;
    int k = l;
    while ( i < m || j < r )
    {
        if ( i<m && (b[i] < b[j] || j >= r) )
        {
            a[k] = b[i];
            i++;
        }
        else
        {
            a[k] = b[j];
            j++;
        }
        k++;
    }
}
void merge ( int b [ ] , int a [ ] , int l , int m , int r ) { int i = l ; int j = m ; int k = l ; while ( i < m || j < r ) { if ( i < m && ( b [ i ] < b [ j ] || j >= r ) ) { a [ k ] = b [ i ] ; i ++ ; } else { a [ k ] = b [ j ] ; j ++ ; } k ++ ; } }
Merge fucntion for the merge sort
Merge fucntion for the merge sort
// index in each array // index in A // while there are elements on each side // copy element from the left array // copy element from the right array