找Palindrome

eyl*_*lay -2 c++ string recursion function palindrome

我想找一个单词的Palindrome.这里有什么不对吗?

主功能:

  int size;
  string input;
  cin>>input;
  size = input.length();  
  if(testPalindrome(input,size-1,0))
    cout<<"It's Palindrome";
  else
    cout<<"It's not Palindrome";
Run Code Online (Sandbox Code Playgroud)

testPalindrome函数是:

bool testPalindrome (string pal , int last, int first){

    if (pal[first] != pal[last])
        return false;
    else{
        if (first<last)
            testPalindrome(pal,last-1,first+1);
        else
            return true;
    }
}
Run Code Online (Sandbox Code Playgroud)

我已阅读此链接并找到了确定Palindromes的答案,但为什么这个不起作用?

mol*_*ilo 6

您需要返回递归调用的结果,就像调用任何其他函数一样.

如果不这样做,则行为未定义.