Search
 
SCRIPT & CODE EXAMPLE
 

CPP

how to declare comparator for set of pair

// custom comparator for set< pair<int,int> > 
struct comp {
	// operator() overloading    
    bool operator() (const pair<int, int>&a, const pair<int, int>&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<pair<int, int>, comp> s;
Comment

PREVIOUS NEXT
Code Example
Cpp :: input output c++ 
Cpp :: print hello world c++ 
Cpp :: eosio check account exist 
Cpp :: sony pictures animation films produced 
Cpp :: c++ convert binary string to decimal 
Cpp :: c++ write to file 
Cpp :: error: ‘memset’ was not declared in this scope in cpp 
Cpp :: c++ converting centimeters to kilometers 
Cpp :: unreal get eobjecttypequery cpp´ 
Cpp :: C++ Area of Scalene Triangle 
Cpp :: every number is coming thrice except one 
Cpp :: gl draw line rectangle 
Cpp :: cpp iterate words from string 
Cpp :: cuda __constant__ 
Cpp :: void value not ignored as it ought to be 
Cpp :: what is time complexity of min_element() 
Cpp :: eosio name to string 
Cpp :: sqrt cpp 
Cpp :: finding no of unique characters in a string c++ 
Cpp :: arduino led code 
Cpp :: c++ vector element search 
Cpp :: c++ loop through array 
Cpp :: compare float values c++ 
Cpp :: tic toc toe c++ 
Cpp :: infinite loop c++ 
Cpp :: how to do (binary) operator overloading in c++ 
Cpp :: c++ iterate over vector 
Cpp :: http.begin() error 
Cpp :: string length c++ 
Cpp :: how print fload wiht 2 decimal in c++ 
ADD CONTENT
Topic
Content
Source link
Name
3+3 =