please help me making the compare function and explaining the logic
String sort - searching sorting challenges
Hi @sarthak051999
In the compare function you should first check from starting of both the strings and return 1 if s1[i] > s2[i] which means that string 1 is to be placed ahead of string 2. And if s2[i] > s1[i] then it should return -1 which means that string 2 is to be placed ahead of string 1. And if both the strings are equal (like in case of bat and batman) then you check which string is smaller and return the larger string first.
Here is the code for the compare function :
1 Like