We use cookies to ensure you have the best browsing experience on our website. Please read our cookie policy for more information about how we use cookies.
In case of equality i think we have some checks and swaps to do according to specification of question , my code , sorry i don't know how to display ut in better way :
Sorting: Comparator
You are viewing a single comment's thread. Return to all comments →
In case of equality i think we have some checks and swaps to do according to specification of question , my code , sorry i don't know how to display ut in better way :
comparator(player A,Player B) {
if(A.score > B.score) return 1; else if(A.score < B.score) return -1; else if(A.score == B.score) sortChars(A.name,B.name); return 0; }
void sortChars(string s1,string s2){
string shorter = s1 < s2 ? s1 : s2;
for(int i =0; i val2){ s1.swap(s2); return; } else { if(val2 > val1) return; } else continue; }
if (shorter == s1) s1.swap(s2); else return; }