C
case.learning
Hi everyone,
I'm a C++ novice. I'm trying to learn recursion and have written this
piece of code but it doesn't work. Could you help me to see where it
goes wrong? Thanks.
bool IsPalindrome(string s, int first, int last)
{
if(last <= first)
return true;
else if(s[first] != s[last])
return false;
else
IsPalindrome(s, first+1, last-1);
}
Note: the function returns false all the time, even though the last
call of recursion return true.
Thanks again.
Mark.
I'm a C++ novice. I'm trying to learn recursion and have written this
piece of code but it doesn't work. Could you help me to see where it
goes wrong? Thanks.
bool IsPalindrome(string s, int first, int last)
{
if(last <= first)
return true;
else if(s[first] != s[last])
return false;
else
IsPalindrome(s, first+1, last-1);
}
Note: the function returns false all the time, even though the last
call of recursion return true.
Thanks again.
Mark.