C++ examples for STL Algorithm:includes
Determine whether one sequence is completely contained in another sequence using algorithm includes
#include <iostream> #include <algorithm> // algorithm definitions #include <iterator> // ostream_iterator using namespace std; int main() //from ww w . j a va 2 s . co m { const int SIZE1 = 10, SIZE2 = 5, SIZE3 = 20; int a1[ SIZE1 ] = { 1, 2, 3, 4, 5, 6, 7, 8, 9, 10 }; int a2[ SIZE2 ] = { 4, 5, 6, 7, 8 }; int a3[ SIZE2 ] = { 4, 5, 6, 11, 15 }; ostream_iterator< int > output( cout, " " ); cout << "a1 contains: "; copy( a1, a1 + SIZE1, output ); // display array a1 cout << "\na2 contains: "; copy( a2, a2 + SIZE2, output ); // display array a2 cout << "\na3 contains: "; copy( a3, a3 + SIZE2, output ); // display array a3 // determine whether set a2 is completely contained in a1 if(includes( a1, a1 + SIZE1, a2, a2 + SIZE2 ) ) cout << "\n\na1 includes a2"; else cout << "\n\na1 does not include a2"; // determine whether set a3 is completely contained in a1 if(includes( a1, a1 + SIZE1, a3, a3 + SIZE2 ) ) cout << "\na1 includes a3"; else cout << "\na1 does not include a3"; }