recursion - what is the base case here in this recursive function?? How its working actually? -


what base case here ?? functional how it's working?

int ispali(char *s, int l, int r) { return ((l == r) || (s[l] == s[r] && ispali(s, l+1, r-1))); } int main() { char str[100]; scanf("%s", str);  if(ispali(str, 0, strlen(str)-1)) printf("palindrome\n"); else printf("not palindrome\n"); } 

it's in line of function. remember short-circuit logic in evaluating expressions. or can changed to

if (l == r)      return true; else     return (s[l] == s[r] && ispali(s, l+1, r-1)); 

of course, can apply short-circuit else part:

else     if s[l] == s[r]         return ispali(s, l+1, r-1);     else         return false; 

Comments

Popular posts from this blog

'hasOwnProperty' in javascript -

How to understand 2 main() functions after using uftrace to profile the C++ program? -

android - Unable to generate FCM token from dynamically instantiated Firebase -