When I run the sample input through my code, the output is:
apple
bat
But, the output should be
apple
batman
bat
I made the complex comparator myself.
Here is it’s code.
bool myCompare(string a, string b){
int m = a.length();
int n = b.length();
int x;
if (m<n)
x=m;
else
x=n;
int check=0;
for (int i=0; i<x; i++)
{
if (a[i]==b[i])
check++;
}
if (check==x)
return a>b;
else
return a<b;
}
Can you suggest where I am going wrong.