As per discussed, for inbuilt sort in compare function for printing output in decreasing order we
return a>b;
While in video to explain how compare function works we use
return a<b;
So how actually compare function works or sort function works in general.
Comparator Function
@naivecoder010 hey bro,comparator function basically hmare sort function ko ye batata hai ki hme sorting krte time kaun si condition lgani hai whether > or< ,aur ye internal sorting hoti hai is comparator ke basis pr aur every elements are compared on basis of this function and are sorted by sort function.
Ha exactly, comparator function is for how the sorting works but, inbuilt sort uses > for descending sort while bubble sort uses < for same, though bubble sort was more understood as if no. is small than swap else its Okay, still having a doubt in it.
@naivecoder010 hey bhai,its not like bubble sort ,ye internal sorting hoti hai which takes nlogn time ,so don’t compare it with bubble sort sign convention just think in that way ki apko agr decreasing me krna hai to comparator bnaya aur internal sorting se us comparator ke through compare hogi aur output degi.Hope you get it
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.