The following program can demonstrates you how to implement the set_intersection() function of the C++ language in the C++ programming as follows :
Code:
#include <algorithm>
#include <vector>
#include <iostream>
using namespace std;
int main ()
{
int fs[] = {5,1,35,2,45};
int sd[] = {5,4,3,2,1};
vector<int> r(10);
vector<int>::iterator c;
sort (fs,fs+5);
sort (sd,sd+5);
c=set_intersection (fs, fs+5, sd, sd+5, r.begin());
cout << "intersection has " << int(c - r.begin()) << " elements.\n";
return 0;
}
The above code can generate the following Output :
Code:
intersection has 2 elements
Bookmarks