Go Back   TechArena Community > Software > Software Development
Become a Member!
Forgot your username/password?
Tags Active Topics RSS Search Mark Forums Read

Reply
 
Thread Tools Search this Thread
  #1  
Old 04-03-2010
Member
 
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!!!
Reply With Quote
  #2  
Old 04-03-2010
Member
 
Join Date: May 2008
Posts: 2,008
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.
Reply With Quote
  #3  
Old 04-03-2010
Member
 
Join Date: Apr 2008
Posts: 2,001
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
Reply With Quote
  #4  
Old 04-03-2010
Member
 
Join Date: May 2008
Posts: 2,293
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 );
Reply With Quote
  #5  
Old 04-03-2010
Member
 
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.
Reply With Quote
  #6  
Old 04-03-2010
Member
 
Join Date: Oct 2005
Posts: 2,389
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;
}
Reply With Quote
Reply

  TechArena Community > Software > Software Development
Tags: , , , ,



Thread Tools Search this Thread
Search this Thread:

Advanced Search


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


All times are GMT +5.5. The time now is 05:43 PM.