irishScott
Lifer
I'm taking a prereq CS class for my major, and one of the labs involves writing a recursive function that determines if a word is a palindrome or not. Easy. The function works fine (as proven by debugging text), but for some reason the return values are messed up (presumably by the recursion).
Here's the function code (C++, minus the debugging text)
bool isAPalindrome(char word[], int frontCursor, int backCursor)
{
if(word[frontCursor] == word[backCursor])
isAPalindrome(word, frontCursor + 1, backCursor - 1);
else if(frontCursor == backCursor)
return true;
else
return false;
}
For some reason, it returns some weird number if more than one recursive cycle is required (ie: 244). Any ideas?
Here's the function code (C++, minus the debugging text)
bool isAPalindrome(char word[], int frontCursor, int backCursor)
{
if(word[frontCursor] == word[backCursor])
isAPalindrome(word, frontCursor + 1, backCursor - 1);
else if(frontCursor == backCursor)
return true;
else
return false;
}
For some reason, it returns some weird number if more than one recursive cycle is required (ie: 244). Any ideas?