includes() in C++

includes(): This function is available in the file std_algo.h. It returns  true if each element in [__first2,__last2) is contained in order within [__first1,__last1). False otherwe.This function determines whether all elements of a sequence exists in a range.

Parameters: Four parameters are required for this function.

__first1– Start of the search range. 

__last1 – End of the search range. 

__first2 – Start of sequence 

__last2 – End of sequence.

Syntax:

includes(__first1, __last1, __first2, __last2)

For Example:

arr = { 1,2,3,4,5}, vec = {2,3,5}

includes(arr.begin(),arr.end(),vec.begin(),vec.end()) = > It return true (1).

Approach

C++

#include <bits/stdc++.h>
using namespace std;

int main()
{
    vector<int> arr = {1, 2, 3, 4, 5};

    vector<int> vec = {2, 3, 5};

    cout << includes(arr.begin(), arr.end(), vec.begin(), 
vec.end()) << "\n";

    return 0;
}


inplace_merge() in C++

inplace_merge(): This function is available in the file stl_algo.h. It merges two sorted ranges in place.

This function does not return anything or we can say that it is of void type. It merges two sorted and consecutive ranges, [__first,__middle) and [__middle,__last), and puts the result in [__first,__last). 

The output will be sorted. The sort is stable, that is, for equivalent elements in the two ranges, elements

Parameters: Three parameters are required for this function.

__first – An iterator. 

__middle – Another iterator.

 __last – Another iterator.

Syntax:

inplace_merge(__first, __middle, __last)

For Example:

arr = {1,6,14,15}, vec= {7,8,10,11}

First of all, copy all the elements into a single array.

inplace_merge(res.begin(),res.begin()+arr.size(),res.end()) =>It merges both arrays and array result becomes ={1,6,7,8,10,11,14,15}

Approach 

C++

#include <bits/stdc++.h>
using namespace std;

int main()
{
    vector<int> arr = {1, 6, 14, 15};
    vector<int> vec = {7, 8, 10, 11};

    sort(arr.begin(), arr.end());
    sort(vec.begin(), vec.end());
    vector<int> res(arr.size() + vec.size());

    vector<int>::iterator it = copy(arr.begin(), arr.end(), 
res.begin());
    copy(vec.begin(), vec.end(), it);
    inplace_merge(res.begin(), res.begin() + arr.size(),
 res.end());

    for (int i = 0; i < res.size(); i++)
        cout << res[i] << " ";

    return 0;
}


ilogbf() in C++

ilogbf(): This function is available in the file math.h. It takes one parameter. This function returns an integral part of the logarithm of |x|, using FLT_RADIX as a base for the logarithm. 

Parameters: One parameter is required for this function. The floating-point value is taken as an argument.

X: The value whose logarithm value is to be determined.

Syntax:

ilogbf(X)

For Example:

ilogbf(10.45) = > It returns 3.

Approach

C++

#include <bits/stdc++.h>
using namespace std;

int main()
{
    float x = 10.5;
    cout << ilogbf(x) << "\n";

    return 0;
}


ilogb() in C++

ilogb(): This function is available in the file math.h. It takes one parameter. This function returns an integral part of the logarithm of |x|, using FLT_RADIX as a base for the logarithm.

Parameters: One parameter is required for this function.

X: The value whose logarithm value is to be determined.

Syntax:

ilogb(X)

For Example:

ilogb(10.45) = > It returns 3.

Approach:

C++

#include <bits/stdc++.h>
using namespace std;

int main()
{
    float x = 10.5;
    cout << ilogb(x) << "\n";

    return 0;
}