How to take set difference of two sets in C++?

Set difference of two sets A and B is defined as the set C consisting of elements from A not present in B.

In C++, algorithm header in STL defines a function set_difference which in conjunction with inserter can be used to take set difference of two sorted range of elements.

Example:

#include<algorithm>

#include<set>

using namespace std;

..

set<int> A, B, C;

..

set_difference(A.begin(), A.end(), B.begin(), B.end(), inserter(C, C.end()))




So, this basically takes the set difference of the whole of A and B and copies those elements to C.

set_difference can even work on vectors and arrays. Just make sure that the vectors and arrays are sorted before you take the set difference.

Complexity: O(n)



13 comments:

  1. This is very nice one and gives indepth information. Thanks for this nice article.
    the best carding forum

    ReplyDelete
    Replies
    1. I am glad that I saw this post. It is informative blog for us and we need this type of blog thanks for share this blog, Keep posting such instructional blogs and I am looking forward for your future posts. Python Projects for Students Data analytics is the study of dissecting crude data so as to make decisions about that data. Data analytics advances and procedures are generally utilized in business ventures to empower associations to settle on progressively Python Training in Chennai educated business choices. In the present worldwide commercial center, it isn't sufficient to assemble data and do the math; you should realize how to apply that data to genuine situations such that will affect conduct. In the program you will initially gain proficiency with the specialized skills, including R and Python dialects most usually utilized in data analytics programming and usage; Python Training in Chennai at that point center around the commonsense application, in view of genuine business issues in a scope of industry segments, for example, wellbeing, promoting and account. Project Center in Chennai

      Delete
  2. They design engineering software solutions for a broad assortment of applications and devices, from device dependent embedded software to mobile solutions and enterprise desktop applications.cheap Revit 2018

    ReplyDelete
  3. Application segments for the global engineering software market are product design and testing, 3D modeling, drafting, design automation, and others.buy SolidWorks 2018

    ReplyDelete
  4. Other programming forums serve a broader horizon and include threads which discuss multiple programming languages and scripting languages like Perl, python and PHP..net forums

    ReplyDelete
  5. It is really great work and the way in which you are sharing the knowledge is excellent. Thanks for your informative article
    Php course in chennai

    ReplyDelete
  6. Torrentsformac
    A free download hub to activate, crack your softwares for windows and you mac. you can download keygen, generator and activators to crack your desired torrentsformac.com

    ReplyDelete
  7. This comment has been removed by a blog administrator.

    ReplyDelete
  8. Since improvement of a custom ERP programming is on premise of your prerequisites, to get an excellent framework that moves around future changes effectively regardless of it being a first-time venture, PR Softwar

    ReplyDelete
  9. Today, I was just browsing along and came upon your blog. Just wanted to say good blog and this article helped me a lot, due to which I have found exactly I was looking. salesflow.io

    ReplyDelete