Hello sir,
Could you please explain the use of
return a > b;
return a.length() > b.length() in compare function??
Sorting based upon length
-
return a>b;
a>b, will check if a is lexicographicaly greater than b or not.
If a is greater than, it will return 1
Else, 0 -
return a.length()>b.length()
length() function is used to calculate the length of string.
So, this statement will sort strings on the basis of their length(no. of cahracters)
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.