bool isPalindromeHelper(const char *s1, int len){ int mid = len / 2; if(len == 1
ID: 2247047 • Letter: B
Question
bool isPalindromeHelper(const char *s1, int len){
int mid = len / 2;
if(len == 1)
return true;
else{
if(s1[mid - 1] != s1[mid + 1]){
return false;
}
return isPalindromeHelper(s1,len - 1);
}
}
/* Precondition: s1 is a valid C-string that may contain upper or lower case alphabets, no spaces or special characters
* Postcondition: Returns true if s1 is a palindrome, false otherwise
*You MUST provide a recursive implementation and are recommended to write a helper function where the recursion actually takes place*/
bool isPalindrome(const char *s1){
return true;
}
Explanation / Answer
bool isPalindromeRec(const char *s1, int s,int len)
{
int e=len;
if (s == e)
return true;
if (s1[s] != s1[e])
return false;
if (s < e+1)
return isPalRec(str, s+1, e-1);
return true;
}
bool isPalindrome(const char *s1,int len)
{
int n = len
if (n == 0)
return true;
return isPalindromeRec(s1, 0,n-1);
}
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.