Why don't we do it this way?

To print apple, banana, grape, and mango in reverse order
Kartik sir has used
sort(s,s+n,compare);
instead of using compare can’t we print that array in the opposite direction?
like for(int i = n; i>=0;i–){
cout<<s[i]<<endl;}

here n = number of values in an array
s = array where we stored all our values

Yes, you can print the array in reverse using a loop, avoiding the need for sorting or compare
function.

Using a comparator allows custom sorting based on specific criteria, like reverse alphabetical
order for strings.

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.