Doubt in question no 5

got the question but which index will be compare to which index and in what order ??

hello @anujsharmabadboy

pls share the problem statement with me

Given the following code snippet :

bool comp(string s1, string s2)
{
if(s1.length() < s2.length())
return 1;
else if(s1.length() > s2.length())
return 0;
else return s1 < s2;
}

vector< string > data = {“b”, “a”, “c”, “abc”, “bca”, “xy”};
sort(data.begin(), data.end(), comp);
for(string item : data)
cout << item << " ";

@anujsharmabadboy

here first we are comparing lengths of string i.e string of smaller size will come first and then larger size.

if lenght of both string is same then we are sorting them lexicographically (dictionary order)
now try to predict output

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.