String Sort for Substrings

How to sort strings, if one is subset of another ?

@Lavanya_511
Here is the pseudo code

str1 = "batman"
str2 = "bat"

int i = 0;
int j = 0;

while(str1[i] != '\0' && str2[j] != '\0') {
if(str1[i] == str2[j]) {
    i++;
    j++;
} else if(str1[i] < str2[j]) {
    // str1 should come first
    break;
} else {
    // str2 should come first  
    break; 
}
} 

if(str1[i] == '\0') {
    // str2 should come first
} 

if(str2[i] == '\0') {
    // str1 should come first
}

Let me know if you still need any help.

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.