Results 1 to 6 of 6

Thread: Implement the set_intersection() in C++

  1. #1
    Join Date
    Dec 2009
    Posts
    33

    Implement the set_intersection() in C++

    I am working in the MNC company as software programmer. We can use the C++ programming language for developing the software at my work place. Thus, I could not know much more about the set_intersection() function of the C++ language. So, I would like to know about the set_intersection() function of the C++ programming language. I also would like to know about how to implement the set_intersection() function of the C++ programming language. Can anyone has the answer for me then reply me. I am waiting for your reply!!!

  2. #2
    Join Date
    May 2008
    Posts
    2,012

    The set_intersection() in C++

    The set_intersection() function algorithm can computes the intersection of the given two sets that can be defined by range [strt1,nd1) and the range [strt2,nd2) and The set_intersection() function can stores the intersection beginning at result. Both the sets, can be given as ranges that can must be sorted in an ascending order. The set_intersection() function can returns value of an iterator that can be to the end of the intersection range. The set_intersection() function can runs in a linear time.

  3. #3
    Join Date
    Apr 2008
    Posts
    2,005

    Implement the set_intersection() in C++

    The following program can demonstrates you how to implement the set_intersection() function of the C++ language in the C++ programming as follows :
    Code:
    #include <algorithm>
    #include <vector>
    #include <iostream>
    using namespace std;
    int main () 
    {
      int fs[] = {5,1,35,2,45};
      int sd[] = {5,4,3,2,1};
      vector<int> r(10);       
      vector<int>::iterator c;
      sort (fs,fs+5);     
      sort (sd,sd+5);   
      c=set_intersection (fs, fs+5, sd, sd+5, r.begin());
      cout << "intersection has " << int(c - r.begin()) << " elements.\n";
      return 0;
    }
    The above code can generate the following Output :
    Code:
    intersection has 2 elements

  4. #4
    Join Date
    May 2008
    Posts
    2,297

    set_intersection() in C++

    The set_intersection() function can be used to constructs a range that can be sorted starting in the place that can be pointed by result with the given set of intersection of the two ranges [fst1,lst1) and range [fst2,lst2) that can be sorted as content. The intersection of two given sets can be formed only by the elements that can represent in both of the sets at the same time. The following can be the syntax of the set_intersection() function in the C++ language as follows :
    Code:
    template <class InptItrtr1, class InptItrtr2, class OtptItrtr>
      OtptItrtr set_intersection ( InptItrtr1 first1, InptItrtr1 last1,
                                 InptItrtr2 first2, InptItrtr2 last2,
                                OtptItrtr result );

  5. #5
    Join Date
    Nov 2005
    Posts
    1,323

    Re: Implement the set_intersection() in C++

    The following can be the parameters of the set_intersection() function of the C++ language as :
    1. fst2, lst2 : These parameters of the set_intersection() function can contains an input iterators to the final and starting positions of the given second sequence. The range used can be as [fst2,lst2).
    2. fst1, lst1 : These parameters of the set_intersection() function can contains an input iterators to the final and starting positions of the given first sequence. The range used can be as [fst1,lst1) that can contains all of an elements between fst1 and lst1 including an element that can be pointed by fst1 but not an element that can be pointed by lst1.

  6. #6
    Join Date
    Oct 2005
    Posts
    2,393

    Re: Implement the set_intersection() in C++

    The code that can be mentioned below also states you about the working of the set_intersection() function of the C++ language :
    Code:
    #include <iostream>
    #include <cassert>
    #include <algorithm>
    #include <vector>
    using namespace std;
    int main()
    {
      bool result;
      string h("abcde");
      string h2("aeiou");
      vector<char> vt1(h.begin(), h.end());
      vector<char> vt2(h2.begin(), h2.end());
      vector<char> setIntersection;
      set_intersection(vt1.begin(), vt1.end(),vt2.begin(), vt2.end(),
                     back_inserter(setIntersection));
      for(int g=0; g<setIntersection.size(); g++)
    {
        cout << setIntersection[g];
    }
      return 0;
    }

Similar Threads

  1. How to implement sum() faster in c#?
    By Luis-Fernando in forum Software Development
    Replies: 4
    Last Post: 27-02-2010, 09:25 PM
  2. How can I implement the remove() in CPP
    By Servant in forum Software Development
    Replies: 5
    Last Post: 22-02-2010, 04:18 PM
  3. Implement the copy_backward() in C++
    By Agustíne in forum Software Development
    Replies: 5
    Last Post: 16-02-2010, 09:46 PM
  4. How to implement IP Sec
    By Enriquee in forum Technology & Internet
    Replies: 5
    Last Post: 12-01-2010, 06:28 AM
  5. Want to implement differentiation in C++
    By ADEN in forum Software Development
    Replies: 1
    Last Post: 25-10-2008, 06:13 PM

Tags for this Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Page generated in 1,711,707,633.77375 seconds with 17 queries