C++ examples for STL Algorithm:set_symmetric_difference
Create the symmetric difference between two 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()/* w ww . ja v a2 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; // Create the symmetric difference between lst1 and lst2. res_end = set_symmetric_difference(lst1.begin(), lst1.end(), lst2.begin(), lst2.end(), result.begin()); show_range("Symmetric difference of lst1 and lst2: ", result.begin(), res_end); cout << endl; 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; }