STL Inbuilt Sort function

When we use comparator then why we return a>b.
As for descending it should be a<b.Means to say that if a will be less than b than only swap as we want sorted array in descending order.

the comparator works exactly opposite of what you assumed.
the trick to remember it is that:
if a<b then a should come before b, so return true ( this will create array sorted in ascending order)
else return false
if a>b then a should come before b, so return true ( this will create array sorted in descending order)

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.