merge(beg1, end1, beg2, end2, beg3)
:- This function merges two sorted containers and stores them in a new container in sorted order (merge sort). It takes 5 arguments, first and the last iterator of 1st container, first and the last iterator of 2nd container and 1st iterator of the resultant container.
vector<int> v1 = {1, 3, 4, 5, 20, 30};
vector<int> v2 = {1, 5, 6, 7, 25, 30};
vector<int> v3(12);
merge(v1.begin(), v1.end(), v2.begin(),
v2.end(), v3.begin());
inplace_merge(beg1, beg2, end)
:- This function is used to sort two consecutively placed sorted ranges in a single container. It takes 3 arguments, an iterator to the beginning of 1st sorted range, an iterator to the beginning of 2nd sorted range, an iterator to the last position.
vector<int> v2 = {1, 5, 6, 7, 25, 30};
vector<int> v3(12);
// using copy to copy both vectors into
// one container
auto it = copy(v1.begin(), v1.end(), v3.begin());
copy(v2.begin(), v2.end(), it);
// Using inplace_merge() to sort the container
inplace_merge(v3.begin(),it,v3.end()); ```
set_union(beg1, end1, beg2, end2, beg3)
:- This function computes the set union of two containers and stores them in a new container . It returns the iterator to the last element of the resultant container. It takes 5 arguments, the first and the last iterator of the 1st container, the first and last iterator of the 2nd container, and 1st iterator of the resultant container. The containers should be sorted and it is necessary that the new container is resized to a suitable size.
set_intersection(beg1, end1, beg2, end2, beg3)
:- This function computes the set intersection of two containers and stores it in a new container . It returns the iterator to the last element of the resultant container. It takes 5 arguments, the first and the last iterator of 1st container, the first and the last iterator of the 2nd container, and 1st iterator of the resultant container. The containers should be sorted and it is necessary that the new container is resized to a suitable size.
vector<int> v2 = {1, 5, 6, 7, 25, 30};
vector<int> v3(10);
vector<int> v4(10);
auto it = set_union(v1.begin(), v1.end(), v2.begin(),
v2.end(), v3.begin());
auto it1 = set_intersection(v1.begin(),v1.end(),
v2.begin(), v2.end(), v4.begin());```
set_difference(beg1, end1, beg2, end2, beg3)
:- This function computes the set difference of two containers and stores them in a new container. It returns the iterator to the last element of the resultant container. It takes 5 arguments, the first and the last iterator of the 1st container, the first and the last iterator of the 2nd container, and 1st iterator of the resultant container. The containers should be sorted and it is necessary that the new container is resized to a suitable size.
set_symmetric_difference(beg1, end1, beg2, end2, beg3)
:- This function computes the set symmetric difference of two containers and stores it in a new container . It returns the iterator to the last element of the resultant container. It takes 5 arguments, the first and the last iterator of the 1st container, the first and the last iterator of the 2nd container, and 1st iterator of the resultant container. The containers should be sorted and it is necessary that the new container is resized to a suitable size.
vector v1 = {1, 3, 4, 5, 20, 30};
vector<int> v2 = {1, 5, 6, 7, 25, 30};
// Declaring resultant vector
// for difference
vector<int> v3(10);
// Declaring resultant vector
// for symmetric_difference
vector<int> v4(10);
// using set_difference() to compute difference
// of 2 containers v1 and v2.
auto it = set_difference(v1.begin(), v1.end(),
v2.begin(), v2.end(), v3.begin());
// using set_symmetric_difference() to compute
// symmetric_difference/ of 2 containers
auto it1 = set_symmetric_difference(v1.begin(),
v1.end(), v2.begin(), v2.end(), v4.begin()); ```