According to me this solution should work, but it isn’t. Can you please give me a hint to solve this problem named string sort.
my code is - https://ide.codingblocks.com/s/167632
What's wrong in this approach?
hey @adarsh_anand, you comparator code need to be changed. Please make following changes
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) // means there is a prefix match
return l1>l2; // so sort decreasing order of length
else
return a<b; //sorting in normal dictionary order when no prefix match
}
1 Like
hey @adarsh_anand , if your query is resolved. Please mark this doubt as resolved and rate me on the basis of your experience.
rating option will appear when to mark this doubt as resolved