1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50
|
#include <iostream>
#include <algorithm>
#include <vector>
using namespace std;
struct record
{
record() { i = j = 0; }
record(int i, int j) : i(i), j(j) {}
int i, j;
bool operator<(const record & r) const
{
if (i<r.i) return true;
if (i>r.i) return false;
//now, i==r.i
//if we want to keep records with
//high j, we have to put them first
if (j>r.j) return true;
return false;
}
bool operator==(const record & r) const {return i==r.i;}
};
ostream& operator<<(ostream& os, const record& r)
{
os << '(' << r.i << ',' << r.j << ')'; return os;
}
int main()
{
record elements[] = { record(0, 0), record(0, 1),
record(0, 2), record(1, 0), record(1, 3) };
vector<record> v(elements, elements + 5);
sort(v.begin(),v.end());
v.erase(unique(v.begin(),v.end()),v.end());
for (size_t i = 0; i != v.size(); ++i)
cout << v[i] << " ";
cout << endl; cin.get();
return 0;
}
|