how to declare comparator for set of pair

[ad_1]

how to declare comparator for set of pair
// custom comparator for set< pair >
struct comp {
	// operator() overloading
    bool operator() (const pair&a, const pair&b){
        if((a.second - a.first)  > (b.second - b.first)){
            return true;
        }
        else if(a.second - a.first == b.second - b.first){
            return a.first < b.first;
        }
        return false;
    }
};

// declaration of set
set, comp> s;

[ad_2]

Please follow and like us:
Content Protection by DMCA.com