Out set_union(In1 fi rst1, In1 last1,
In2 fi rst2, In2 last2, Out result);
template
Out set_union(In1 fi rst1, In1 last1,
In2 fi rst2, In2 last2, Out result, Compare comp);
Жиындармен жұмыс істеу алгоритмдерін қолдану мысалы
#include
#include
using namespace std;
void show(const char *s, const int *begin, const int *end){
cout << s << " ";
copy(begin, end, ostream_iterator(cout, " "));
cout << endl;
}
int main(){
int a[4] = {2, 5, 7, 9}, b[3] = {1, 5, 9},
Union[7], *p_union,
isect[4], *p_isect,
dif[3], *p_dif,
symdif[7], *p_symdif;
p_isect = set_intersection(a, a + 4, b, b + 3, isect);
p_union = set_union(a, a + 4, b, b + 3, Union);
p_dif = set_difference(a, a + 4, b, b + 3, dif);
p_symdif = set_symmetric_difference(a, a + 4, b,
b + 3, symdif);
show("a: ", a, a + 4);
show("b: ", b, b + 3);
show("isect: ", isect, p_isect);
show("Union: ", Union, p_union);
show("dif: ", dif, p_dif);
show("symdif:", symdif, p_symdif);
if (includes(a, a + 4, b, b + 3))
cout << "a b-ны қамтиды.\n";
else cout << "a b-ны қамтымайды.\n";
if (includes(Union, p_union, b, b + 3))
Достарыңызбен бөлісу: |