Guest User

Untitled

a guest
Nov 21st, 2017
104
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.57 KB | None | 0 0
  1. struct S
  2. {
  3. int x;
  4. int freq;
  5.  
  6. S(int X, int F)
  7. {
  8. x = X, freq = F;
  9. }
  10. };
  11. bool compare(const S &a, const S &b)
  12. {
  13. if (a.freq != b.freq) return a.freq > b.freq;
  14. return a.x < b.x;
  15. }
  16. int main()
  17. {
  18. std::set<S> my_set; //custom compare
  19.  
  20. my_set.find(S(10, 11)); //find first element with x = 10
  21. my_set.insert(S(20, 30)); //normal insertion
  22. my_set.erase(S(20, 30)); //erase element with x = 20 && freq = 30
  23.  
  24. cout << my_set.size() << endl;
  25.  
  26. }
Add Comment
Please, Sign In to add comment