Search
 
SCRIPT & CODE EXAMPLE
 
CODE EXAMPLE FOR CPP

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
}
Source by stackoverflow.com #
 
PREVIOUS NEXT
Tagged: #custom #comparator #elements #set
ADD COMMENT
Topic
Name
3+2 =