when we define the compare function in the code how it actually works?
And why the return type is bool?
I am not able to understand it properly.
Compare function for sort() function
@sengarankit98 Sort without any custom comparator(third argument) will sort elements in ascending order. When you want to sort in any other fashion, you need to use a compare function.
We can also write our own comparator function and pass it as a third parameter. 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. Internal swapping occurs (same as an manual sorting) when the compare function returns true.