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<intarr = {12345};

    vector<intvec = {235};

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

    return 0;
}


No comments:

Post a Comment