Sir/ ma’am ,
I want to know how compare(Mycompare) parameter in sort function works as in this question i have no clue how it works.
int Mycompare(string X, string Y){
string XY = X.append(Y);
string YX = Y.append(X);
int val = XY.compare(YX) > 0 ? 1:0 ;
if (val == 0){
cout <<Y<<" "<<X<<" "<< YX<< "val - 0" << endl;
}
else{
cout <<X<<" "<<Y<<" "<<XY<< "val - 1" << endl;
}
return XY.compare(YX) > 0 ? 1:0 ;
}
I tried printing the value but couldn’t understand the outputs
56454 5456454 56454val - 1
564548564 548564 564548564val - 0
54854 5454854 54854val - 1
564548564 548564 564548564val - 0
9564 5649564 9564val - 1
Input : - 54 564 548 9
