recursive function for palindrome

im trying 2 write a recursive function which returns true if the string is a palindrome and otherwise false.

bool isPalindrome(string s)
{
if (s.empty())
return false;




and thats as far as i got
can ne1 help me?



What is your base case? In other words, when can you always be sure you have a palindrome?

How will you take the current string closer to the base case? What condition must it meet to remain in consideration for a palindrome?

(By the way, your if statement won't work if you consider a string with 0 characters a palindrome, or a string with 1 character a palindrome.)
closed account (z05DSL3A)
This is a possible signature for a recursive function; obviously you will have to test the criteria under which the recursion would continue. Will you ignore spaces and punctuation. Eg. "Neil, a trap! Sid is part alien!" or "Mr. Owl ate my metal worm".

1
2
3
4
5
6
bool isPalindrome(const string& str, int firstLetter, int lastLetter)
{
    ....
    ....  return  isPalindrome(str, ++firstLetter, --lastLetter);
    ....
}
Topic archived. No new replies allowed.