Answers for "c++ custom comparator for elements in set"

C++
2

c++ custom comparator for elements in set

struct compare {
    bool operator() (const int& x, const int& y) const {
        return x<y; // if x<y then x will come before y. Change this condition as per requirement
    }
};
int main()
{
  set<int,compare> s; //use the comparator like this
}
Posted by: Guest on December-06-2020

Code answers related to "c++ custom comparator for elements in set"

Browse Popular Code Answers by Language