the compare function is of bool type so it will return 0 or 1 means if we write
bool compare(string a, string b)
{
return a.length()>b.length();
}
it will return 1 if a.length is greater then b.length
sooo that means we have passed 1 in sort
that is
sort(s,s+n,1)
how does sort know that which amongst all the elements in s is bigger ?
Compare function in sorting string
That is because the return type maybe bool but the function definition is not as linear as compare where it is straightaway comparing the length of the two strings.
Remember, just because the return type is a binary value does not mean that the comparisons are also binary in nature. they can be complex operations where for some classes it may be returning true and for others false