I am not able to understand, what the comparator is doing like how it acheving its target, when passed in function

I am not able to understand, what the comparator is doing like how it acheving its target, when passed in function

@ashishnnnnn in the sort function, we provide the name of the function. Please note that we dont CALL the function, we just pass its address. (to call the funcn we’d need to add parantheses as well, which we didnt)
the sort function sorts the elements according to the compare function, so it passes two elements, the compare function compares them and returns a boolean value indicating whether they are in the correct order or not, and the sort function will do rest of the work.

if you want the values to be in ascending order, return a < b which means that a is less than b is the correct order which implies ascending order. Similarly, a > b would mean that a is greater than b is the correct order and that would imply descending order.

I hope it is clear to you now. Dont forget to mark the doubt as resolved!

1 Like

I hope I’ve cleared your doubt. I ask you to please rate your experience here
Your feedback is very important. It helps us improve our platform and hence provide you
the learning experience you deserve.

On the off chance, you still have some questions or not find the answers satisfactory, you may reopen
the doubt.