#1
 D-Mon Member Join Date: Jan 2010 Posts: 26
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.
#2
 Reegan Member Join Date: Oct 2005 Posts: 2,389
The set_union() in C++

The set_union() function algorithm can be used to compute the sorted union of the two given specified ranges [strt1,nd1) and [strt2,nd2) that can be sorted and The set_union() function can stores it can begins at rslt. The set_union() function can returns value of an iterator to the end of the range that can be union. The set_union() function can runs in a linear time. I hope this information can be enough for you to know about the set_union() function of the C++ language.
#3
 opaper Member Join Date: May 2008 Posts: 2,383
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`
__________________
The FIFA Manager 2009 PC Game
#4
 MindSpace Member Join Date: Feb 2008 Posts: 1,848
The set_union()

The set_union() function can be used to set union of the two given specified ranges that can be sorted. The set_union() function can constructs a range that can be sorted at beginning in the location that can be pointed by the result with the set of union of the two ranges [fst1,lst1) and [fst2,lst2) that can be sorted as content. The following can be the syntax of the set_union() function in the C++ language as follows :
Code:
```template <class InptItrtr1, class InptItrtr2, class OtptItrtr>
OtptItrtr set_union ( InptItrtr1 first1, InptItrtr1 last1,
InptItrtr2 first2, InptItrtr2 last2,
OtptItrtr result );```
#5
 Modifier Member Join Date: Jan 2008 Posts: 1,515
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.
#6
 Praetor Member Join Date: Apr 2008 Posts: 1,948
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 :
Code:
`abcdeiou`

 Tags:

 Thread Tools Search this Thread Show Printable Version Email this Page Search this Thread: Advanced Search

All times are GMT +5.5. The time now is 05:44 PM. 