Doubt in "String sort"

The testcase 2 show run-error .
my code is following :

@76rahul257 For substring/prefix check, you are only checking the first character as in line 8 which is wrong.
So consider two strings bat,bits, you code will sort in order keeping bits before bat.
Make your mycompare function something like this:
bool mycompare( string a, string b)
{
int l1=a.length();int l2=b.length();int flag=-1;
for(int i=0;i<min(l1,l2);i++){
if(a[i]!=b[i])
flag=0;
}
if(flag==-1)
return l1>l2;
else
return a<b;
}

After applying that code the testcase 2 also show run-error…

@76rahul257 Please share the link of your code you have modified.

Here my updated code

Still your compare function was wrong. Just dry run and check the logic you have used in the compare function.Also in line 22 , you had set the string length to 50 which was causing run error for longer strings.
Check this, i have corrected 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.