pset3/find/helpers_merge.c
bool search(int value, int values[], int n)
{
    // array size cannot be negative
    if (n < 0)
    {
        return false;
    }
    
    // set right, left and middle bounds
    int r = n -1;
    int l = 0;
    int m;
    while (l <= r)
    {
        
        // calculate middle
        m = (l + r)/2;
        if (values[m] == value)
        {
            
            // value found
            return true;
        }
        else
        {
            if (value < values[m])
            {
                
                // search to the left (move the right boundary)
                r = m - 1;
            }
            else // value > values[m]
            {
                
                // search to the right (move the left boundary)
                l = m + 1;
            }
        }
    }

    // nothing found
    return false;
}
/**
 * Returns true if value is in array of n values, else false.
 */
Returns true if value is in array of n values, else false.
Returns true if value is in array of n values else false .
bool search(int value, int values[], int n)
{
    if (n < 0)
    {
        return false;
    }
    int r = n -1;
    int l = 0;
    int m;
    while (l <= r)
    {
        m = (l + r)/2;
        if (values[m] == value)
        {
            return true;
        }
        else
        {
            if (value < values[m])
            {
                r = m - 1;
            }
            else 
            {
                l = m + 1;
            }
        }
    }
    return false;
}
bool search ( int value , int values [ ] , int n ) { if ( n < 0 ) { return false ; } int r = n - 1 ; int l = 0 ; int m ; while ( l <= r ) { m = ( l + r ) / 2 ; if ( values [ m ] == value ) { return true ; } else { if ( value < values [ m ] ) { r = m - 1 ; } else { l = m + 1 ; } } } return false ; }
Returns true if value is in array of n values, else false.
Returns true if value is in array of n values else false .
// array size cannot be negative // set right, left and middle bounds // calculate middle // value found // search to the left (move the right boundary) // value > values[m] // search to the right (move the left boundary) // nothing found