C++ examples for STL Algorithm:includes
Use includes() to check the sub list
#include <iostream> #include <list> #include <algorithm> using namespace std; template<class InIter> void show_range(const char *msg, InIter start, InIter end); int main()//from ww w . ja va2 s . co m { list<char> lst1, lst2, result(15), lst3; list<char>::iterator res_end; for(int i=0; i < 5; i++) lst1.push_back('A'+i); for(int i=3; i < 10; i++) lst2.push_back('A'+i); show_range("Contents of lst1: ", lst1.begin(), lst1.end()); cout << endl; show_range("Contents of lst2: ", lst2.begin(), lst2.end()); cout << endl; // Use includes() to check for subset. lst3.push_back('A'); lst3.push_back('C'); lst3.push_back('D'); if(includes(lst1.begin(), lst1.end(), lst3.begin(), lst3.end())) cout << "lst3 is a subset of lst1\n"; else cout << "lst3 is not a subset of lst1\n"; return 0; } // Show a range of elements. template<class InIter> void show_range(const char *msg, InIter start, InIter end) { InIter itr; cout << msg; for(itr = start; itr != end; ++itr) cout << *itr << " "; cout << endl; }