Compare function not giving same result

hi team,
My program is not sorting numbers.
can you tell me why my compare function is not working

#include
#include
#include
#include
using namespace std;

bool compare(string x,string y){
int i=0;
while(x[i]==y[i] && x[i]!=’\0’ && y[i]!=’\0’)
i++;
if(x[i]==’\0’)
return 1;
else if(y[i]==’\0’)
return 0;
else if(x[i]-β€˜0’>y[i]-β€˜0’)
return 0;
else return 1;
}

int main(){
#ifndef ONL
freopen(β€œinput.txt”,β€œr”,stdin);
freopen(β€œoutput.txt”,β€œw”,stdout);
#endif
int t,n;
cin>>t;
while(t–){
cin>>n;
vector arr;

	for(int i=0;i<n;i++){
		string temp;
		cin>>temp;
		arr.push_back(temp);
	}
	sort(arr.begin(),arr.end(),compare);
	for(int i=0;i<n;i++)
		cout<<arr[i];
	cout<<endl;
}

return 0;

}

take a look at these two case
4
54 546 548 60
8
1 34 3 98 9 76 45 4

int the first one to make biggest no we have to place 548 in front of 54
whereas in second case we have to place 9 in front of 98

i hope you understand what i am trying to say

your logic is handeling all tescase

correct compare function should be like

bool compare(string x, string y) {
    string XY = X.append(Y); 
    string YX = Y.append(X); 
    return XY.compare(YX) > 0 ? 1: 0; 
}

i hope this help
if you have more doubts regarding this feel free to ask
if your doubt is resolved mark it as resolved from your doubt section inside your course