C++ Program to Implement Set_Symmetric_difference in STL

This C++ Program demonstrates implementation of Set_Symmetric_difference in STL.

Here is source code of the C++ Program to demonstrate Set_Symmetric_difference in STL. The C++ program is successfully compiled and run on a Linux system. The program output is also shown below.

  1. /*
  2.  * C++ Program to Implement Set_Symmetric_difference in Stl
  3.  */
  4. #include <iostream>
  5. #include <algorithm>
  6. #include <vector>
  7. using namespace std;
  8. int main ()
  9. {
  10.     int f[] = {5,10,15,20,25};
  11.     int s[] = {50,40,30,20,10};
  12.     vector<int> v(10);
  13.     vector<int>::iterator it;
  14.     sort (f, f + 5);
  15.     sort (s, s + 5);
  16.     it = set_symmetric_difference(f, f + 5, s, s + 5, v.begin());
  17.     v.resize(it - v.begin());
  18.     cout<<"The symmetric difference has "<< (v.size())<< " elements: "<<endl;
  19.     for (it = v.begin(); it != v.end(); ++it)
  20.         cout<< *it<<"  ";
  21.     cout <<endl;
  22.     return 0;
  23. }

$ g++ set_Symmetric_difference.cpp
$ a.out
The symmetric difference has 6 elements: 
5  15  25  30  40  50  
 
 
------------------
(program exited with code: 0)
Press return to continue

Sanfoundry Global Education & Learning Series – 1000 C++ Programs.

advertisement
advertisement
If you wish to look at all C++ Programming examples, go to C++ Programs.

advertisement
advertisement
Subscribe to our Newsletters (Subject-wise). Participate in the Sanfoundry Certification contest to get free Certificate of Merit. Join our social networks below and stay updated with latest contests, videos, internships and jobs!

Youtube | Telegram | LinkedIn | Instagram | Facebook | Twitter | Pinterest
Manish Bhojasia - Founder & CTO at Sanfoundry
Manish Bhojasia, a technology veteran with 20+ years @ Cisco & Wipro, is Founder and CTO at Sanfoundry. He lives in Bangalore, and focuses on development of Linux Kernel, SAN Technologies, Advanced C, Data Structures & Alogrithms. Stay connected with him at LinkedIn.

Subscribe to his free Masterclasses at Youtube & discussions at Telegram SanfoundryClasses.