Use of the set_union() in C++
I am interested in doing the programming. Thus, I had just started for learning the C++ programming language. I can also have the knowledge of the basic working of the functions. Hence, I want to know what is the set_union() function of the C++ language. I also want to know what is the use of the set_union() function in the C++ programming. Can anyone knows about the set_union() function of C++ language.
Use of the set_union() in C++
The following program can demonstrates you how to implement the set_union() function of the C++ language in the C++ programming as follows :
Code:
#include <vector>
#include <algorithm>
#include <iostream>
using namespace std;
int main ()
{
int fst[] = {15,1,5,2,6};
int scnd[] = {5,4,3,2,1};
vector<int> w(10);
vector<int>::iterator t;
sort (fst,fst+5);
sort (scnd,scnd+5);
t=set_union (fst, fst+5, scnd, scnd+5, w.begin());
cout << "union has " << int(t - w.begin()) << " elements.\n";
return 0;
}
Output:
Code:
union has 8 elements
Re: Use of the set_union() in C++
The following can be the parameters of the set_union() function of the C++ language as :
1. fst2, lst2 : These parameters of the set_union() function can contains an input iterators to the final and starting positions of the given second sequence. The range used can be as [fst2,lst2).
2. fst1, lst1 : These parameters of the set_union() function can contains an input iterators to the final and starting positions of the given first sequence. The range used can be as [fst1,lst1) that can contains all of an elements between fst1 and lst1.
Re: Use of the set_union() in C++
PROGRAM :
Code:
#include <iostream>
#include <cassert>
#include <algorithm>
#include <vector>
using namespace std;
int main()
{
bool rslt;
string t("abcde");
string t2("aeiou");
vector<char> vctr1(t.begin(), t.end());
vector<char> vctr2(t2.begin(), t2.end());
vector<char> setUnion;
set_union(vctr1.begin(), vctr1.end(),vctr2.begin(), vctr2.end(),
back_inserter(setUnion));
for(int j=0; j<setUnion.size(); j++)
{
cout << setUnion[j];
}
return 0;
}
OUTPUT :