Doubt in finding prefix in the string

How to to find the prefix of a string in another string and then how to sort the string accordingly

@rg361 You have to make compareTo Function like this for comparing the strings :

int compareTo(string s1, string s2) {

        int i = 0;      

        while (i < s1.length() && i < s2.length()) {

            if (s1[i] > s2[i]) {

                return 1;
            } else if (s1[i] < s2[i]) {
                return -1;
            }
            i++;

        }

        if (s1.length() > s2.length()) {
            return -1;
        } else {
            return 1;
        }

    }

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.

Actuallly, I have having problems in my code. Please provide the correct code

@rg361 Refer this article for code and concept.

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.