Comparison parameter in sort STL

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

@sinhadivyam19
string xy is x+y
string yx is y+x
then you are comparing if xy>yx val =1 else val=0
just dry run for the input not taken two at a time.
dont forget to mark resolved and hit like if cleared :smiley:

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.