in the code compare function requires two integer values as parameters but we did not pass any. So is the result a>b based on garbage values?
Please explain inclusion of compare as parameter in sort
Hi @mayankA47, when we pass compare as a parameter in the sort function, we are passing the entire function and we are not calling it. Notice that we do not write ‘compare()’, we just write compare.
The sort function takes a third parameter which is a function and calls it internally by passing parameters. The parameters are two elements of the vector.
So, when we write a>b, we are actually comparing two elements of the vector, suppose integers in this case.
Hope this resolves your query. If you still have any doubt, reply to this thread or mark this doubt as resolved.
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.