The includes() function of C++
I am studying in the MSC-IT. I can have learn the C++ language. I can know the concept of functions. I can learn the functions in the first semester of the BSC-IT in the C language. So, I would like to know about the includes() function of the C++ language. I also would like to know about what is the use of the includes() function of the C++ language. Anyone can help me to know about the includes() function of the C++ language, Reply Me!!!
The includes() function of C++
The includes() function algorithm can returns the true value if each an element in the rang [strt2,nd2) can also be in the range [strt1,nd1). Both of the given specified ranges can must be arranges in an order of ascending. There can no requirement that each an element in the range [strt1,nd1) or in the range [strt2,nd2) can be unique. If some of an element can be appears n times in the range [strt2,nd2), [strt1,nd1) can must contain the similar element at least n times. The < operator can be used to compare an elements, By default.
The includes() function of C++
The following program can demonstrates you that how to use the includes() function in the C++ programming language as follows :
Code:
#include <iostream>
#include <algorithm>
using namespace std;
bool myfunction (int p, int q)
{
return p<q;
}
int main ()
{
int cntnr[] = {5,10,15,20,25,30,35,40,45,50};
int cntnt[] = {40,30,20,10};
sort (cntnr,cntnr+10);
sort (cntnt,cntnt+4);
if ( includes(cntnr,cntnr+10,cntnt,cntnt+4) )
cout << "cntnr includes cntnt!" << endl;
if ( includes(cntnr,cntnr+10,cntnt,cntnt+4, myfunction) )
cout << "cntnr includes cntnt!" << endl;
return 0;
}
Output:
Code:
cntnr includes cntnt!
cntnr includes cntnt!
Re: The includes() function of C++
The following can be the parameters of the includes() function of the C++ language as :
1. fst2, lst2 : These parameters of the includes() function can contains an input iterators to the final and starting positions of the given second sequence that can be checked on whether it can contained in the first sequence or not.
2. fst1, lst1 : These parameters of the includes() function can contains an input iterators to the final and starting positions of the given first sequence that can be checked on whether it can contains the second sequence or not.
The includes() function of C++
The includes() function can runs in a linear time. Here can be the one more example that can help's you to learn the includes() function of the C++ language :
Code:
#include <iostream>
#include <vector>
#include <list>
#include <algorithm>
int main()
{
std::vector<int> vc;
for (int a = 0; a < 10; ++a)
vc.push_back(a);
std::list<int> ls;
ls.push_back(3);
ls.push_back(4);
ls.push_back(5);
if (std::includes(vc.begin(), vc.end(), ls.begin(), ls.end()))
std::cout << "ls is a subset of vc." << std::endl;
else
std::cout << "ls is NOT a subset of vc." << std::endl;
return 0;
}