yes or no

Does this consider a recursive boolean function? yes/no

#include <string>
#include <iostream>

bool IsPalindrome(std::string str){
size_t j = str.length()-1;
size_t i = 0;
for(;i < str.length(); i++)
if((('a'<=str[i]) && (str[i]<='z'))|| (('A'<=str[i]) && (str[i]<='Z')))
break;
for(;j >=0; j-- )
if((('a'<=str[j]) && (str[j]<='z'))|| (('A'<=str[j]) && (str[j]<='Z')))
break;
if(i>=j)
return true;
if(str[i] == str[j])
return IsPalindrome(str.substr(i+1,j-i-1));
else
return false;
}
void main(){
std::string notStr, myString;
myString = "dfaj sk s dla; ";
notStr = IsPalindrome(myString)?"":"NOT ";
std::cout<<'['<<myString<<']'<<" is "<<notStr<<"a Palindrome!\n";
myString = "able was I ere I, saw elba";
notStr = IsPalindrome(myString)?"":"NOT ";
std::cout<<'['<<myString<<']'<<" is "<<notStr<<"a Palindrome!\n";
std::cout<<"Press <Enter> to exit.";
getchar();

}
Last edited on
Yes
Topic archived. No new replies allowed.