Since you are using recursion, one key thing to note is you have to return the output produced by the recursive function. In this case, you need a return statement in the second if.
Here is the working code:
bool testPalindrome (string x){
static int y = 1;
static int z = x.length();
if( (z-y == 1||z-y == 2) && x[x.length() - z] == x[x.length() - y]){
return true;
}
else if(x[x.length() - z] == x[x.length() - y]){
--z;
++y;
return testPalindrome(x);
}
else{
return false;
}
}
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…