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 -

python - ValueError: No axis named 1 for object type <class 'pandas.core.series.Series'> -

java - How to provide dependency injections in Eclipse RCP 3.x? -