Friday, February 22, 2013
set operation
void ThreeCoke()
{
int a[4]={1,2,3,4},b[4]={4,5,6,7};
set<int> A(a,a+4),B(b,b+4);
cout<<"set A: ";
copy(A.begin(),A.end(),ostream_iterator<int>(cout," "));
cout<<endl;
cout<<"set B: ";
copy(B.begin(),B.end(),ostream_iterator<int>(cout," "));
cout<<endl;
set<int> C;
cout<<"Union:";
set_union(A.begin(),A.end(),B.begin(),B.end(),ostream_iterator<int>(cout," "));
cout<<endl;
cout<<"Intersection:";
set_intersection(A.begin(),A.end(),B.begin(),B.end(),inserter(C,C.begin()));
cout<<endl;
copy(C.begin(),C.end(),ostream_iterator<int>(cout," "));
}
Subscribe to:
Post Comments (Atom)
No comments:
Post a Comment