home *** CD-ROM | disk | FTP | other *** search
/ DOS/V Power Report 1997 May / VPR9705A.ISO / VPR_DATA / PROGRAM / CBTRIAL / SETUP / DATA.Z / SET_DIFF.CPP < prev    next >
Text File  |  1997-02-14  |  880b  |  34 lines

  1.  #include <algorithm>
  2.  #include <set>
  3.  
  4.  using namespace std;
  5.  
  6.  int main ()
  7.  {
  8.    //
  9.    // Initialize some sets.
  10.    //
  11.    int a1[10] = {1,2,3,4,5,6,7,8,9,10};
  12.    int a2[6]  = {2,4,6,8,10,12};
  13.  
  14.    set<int, less<int> > all(a1+0, a1+10), even(a2+0, a2+6), odd;
  15.    //
  16.    // Create an insert_iterator for odd.
  17.    //
  18.    insert_iterator<set<int, less<int> > > odd_ins(odd, odd.begin());
  19.    //
  20.    // Demonstrate set_difference.
  21.    //
  22.    cout << "The result of:" << endl << "{";
  23.    copy(all.begin(),all.end(), ostream_iterator<int>(cout," "));
  24.    cout << "} - {";
  25.    copy(even.begin(),even.end(), ostream_iterator<int>(cout," "));
  26.    cout << "} =" << endl << "{";
  27.    set_difference(all.begin(), all.end(), even.begin(), even.end(), odd_ins);
  28.    copy(odd.begin(),odd.end(), ostream_iterator<int>(cout," "));
  29.    cout << "}" << endl << endl;
  30.  
  31.    return 0;
  32.  }
  33.  
  34.