I written a recursive method which returns true if the string passed to it is a palindrome, I cannot seem to see why the logic isnt working. I've thrown in a bunch of 'cout' statement to see where its going wrong but I cannot see why!
Can anyone please help?
Kunal.
Code:
char buffer[] = "radar";
bool isPalindrome( char b[], int lB, int hB );
int main()
{
int lowerBound=0, upperBound=0;
while( buffer[upperBound] != '\0' )
++upperBound;
if( isPalindrome( buffer, lowerBound, upperBound ) )
cout << buffer << " IS a palindrome." << endl;
else
cout << buffer << " IS NOT a palindrome." << endl;
return 0;
}
bool isPalindrome( char b[], int lB, int hB )
{
if( lB == hB )
return true;
else if( b[lB] == b[hB] )
return isPalindrome( b, lB+1, hB-1 );
else
return false;
}
Can anyone please help?
Kunal.