Ok so I am trying to check if two words are mirror of each other. For example, string1 = abc and string2 = cba they are mirror of each other.
The 1st loop is for string1 and 2nd loop string2. I compare the first char of string 1 to the last char of string 2 and then work my way in. Still trying to find a way to make it simpler than this if possible.
1 2 3 4 5 6 7 8 9 10 11
for (int i = 0; i < length1 - 1; i++)
{
for (int j = length2 - 1; j > 0; --j)
{
if (string1[i] == string2[j])
{
returntrue;
}
}
}
If string1 = "abc," string2 = "cba", then string1[2] == string[0]
If you combine that with the length of the string then the single loop will do.
You can also go one step further and use begin(), end() functionality in the same single only loop structure.