Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- struct S
- {
- int x;
- int freq;
- S(int X, int F)
- {
- x = X, freq = F;
- }
- };
- bool compare(const S &a, const S &b)
- {
- if (a.freq != b.freq) return a.freq > b.freq;
- return a.x < b.x;
- }
- int main()
- {
- std::set<S> my_set; //custom compare
- my_set.find(S(10, 11)); //find first element with x = 10
- my_set.insert(S(20, 30)); //normal insertion
- my_set.erase(S(20, 30)); //erase element with x = 20 && freq = 30
- cout << my_set.size() << endl;
- }
Add Comment
Please, Sign In to add comment