[ create a new paste ] login | about

Link: http://codepad.org/IuYjFMxV    [ raw code | output | fork ]

aaronla - C++, pasted on Oct 31:
#include <iostream>
#include <iomanip>
#include <set>
#include <algorithm>
#include <iterator>

using namespace std;

set<int>& operator<<(set<int>& s, int x){
    s.insert(x); return s;
}

int main(){
    set<int> a, b;
    a << 1 << 3 << 4 << 5;
    b << 2 << 3 << 4 << 6;

    cout << "set 1:  ";
    copy(a.begin(), a.end(), ostream_iterator<int>(cout, " "));
    cout << "\n";

    cout << "set 2:  ";
    copy(b.begin(), b.end(), ostream_iterator<int>(cout, " "));
    cout << "\n";
    
    cout << "intersection:  ";
    set_intersection(a.begin(), a.end(), b.begin(), b.end(),
                     ostream_iterator<int>(cout, " "));
    cout << "\n";

    cout << "difference:  ";
    set_difference(a.begin(), a.end(), b.begin(), b.end(),
                     ostream_iterator<int>(cout, " "));
    cout << "\n";

    cout << "union:  ";
    set_union(a.begin(), a.end(), b.begin(), b.end(),
                     ostream_iterator<int>(cout, " "));
    cout << "\n";
}


Output:
1
2
3
4
5
set 1:  1 3 4 5 
set 2:  2 3 4 6 
intersection:  3 4 
difference:  1 5 
union:  1 2 3 4 5 6 


Create a new paste based on this one


Comments: