not able to understand working of compare in this code, can you explain me the difference in working of code 1 and code 2
also i already watch compare function concept in sort_function video ,in that i didn’t face any problem
not able to understand working of compare in this code, can you explain me the difference in working of code 1 and code 2
also i already watch compare function concept in sort_function video ,in that i didn’t face any problem
@aattuull return a <= b will return true if a <= b, and will return false only when a > b, hence returning false for the first number that is greater than the key, hence working as the upper bound function. This is why it gives the output as 10, because it is the first index whose value returns false for the given key and condition.
On the other hand, return a > b returns false if a <= b, which will be the case for any value less than or equal than the key. In fact, in a sorted array, the 0th element will always be less than or equal to the key (if key is present in the array) this is why your second compare function will always return the answer as 0.
Please mark the doubt as resolved if the difference is clear to you.
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.