What conditions i am missing in my code

Not able to obtain desired output. Please point out the error.
link to my code-https://ide.codingblocks.com/s/221636

Hello @pulkit_pandey09,

There are many logical mistakes in your comparator function.

Corrected code:

Hope, this would help.
Let me know if you still face any issue.

Return type of comparator function is bool . so shouldn’t we return true or false.

Hello @pulkit_pandey09,

That’s exactly what the corrected function is doing.
As the return statements are followed by logical statement and the result of that statement is itself a boolean value i.e. true or false.

thanks for clearing my doubts.

Hello @pulkit_pandey09,

You have to understand what happens when the function returns true and when it returns false.
Suppose you are accepting two elements in this function i.e. the first element is a and the second is b
Then, returning true means the order is correct and a should be placed at left of b.
while returning false means swap their positions, they are not at correct order.

1 Like

Hello @pulkit_pandey09,

Please, mark it as resolved.