Can you list down the instances where we use comparator function and where we have to use comparator class?
In this code, we used class but in sort function we pass comparator function.
Comparator class
Hi this totally depends on function declaration when we have to use comparator function and where we have to use comparator class
Some popular application of comparator class are : - (sorted on usage based on my experience)
- priority_queue STL
- set STL
- multiset STL
- lower_bound
- upper_bound
comparator function is primarily used in sort function
In case of any doubt feel free to ask 
mark your doubt as resolved If you got the answer
1 Like
Thanks for the answer.
I guess in the list in all the cases the comparator class will have the same structure right?
actually in some cases the comparisons differ like return a>b should be return a<b . for that you need to check it using some test cases
1 Like
Thanks.
Yes. That will change.
I just wanted to confirm the constructor structure remains the same or not.