when we call the sort function and send Compare function as a parameter : sort(a, a+n, compare ) then what will happen to compare function as it is a parameterized function and we are not sending any values to a and b in bool campare (int a, int b)
Compare function
Hey @placement sort functions take 3 parameters, one is array, second is it’s size and third is any comparator function designed for certain implementation. Here our bool compare function acts as an comparator which will give instructions to sort function.
This “comparator” function returns a value; convertible to bool, which basically tells us whether the passed “first” argument should be placed before the passed “second” argument or not.
For eg: In the code below, suppose intervals {6,8} and {1,9} are passed as arguments in the “compareInterval” function(comparator function). Now as i1.first (=6) > i2.first (=1), so our function returns “false”, which tells us that “first” argument should not be placed before “second” argument and so sorting will be done in order like {1,9} first and then {6,8} as next.