Minimum number of Appends needed to make a string palindrome | C program to find minimum number of appends needed to make a string Palindrome ; Checking if the string is palindrome or not ; single character is always palindrome ; pointing to first character ; pointing to last character ; Recursive function to count number of appends ; Removing first character of string by incrementing base address pointer . ; Driver program to test above functions
#include <stdio.h> NEW_LINE #include <string.h> NEW_LINE #include <stdbool.h> NEW_LINE bool isPalindrome ( char * str ) { int len = strlen ( str ) ; if ( len == 1 ) return true ; char * ptr1 = str ; char * ptr2 = str + len - 1 ; while ( ptr2 > ptr1 ) { if ( * ptr1 != * ptr2 ) return false ; ptr1 ++ ; ptr2 -- ; } return true ; } int noOfAppends ( char s [ ] ) { if ( isPalindrome ( s ) ) return 0 ; s ++ ; return 1 + noOfAppends ( s ) ; } int main ( ) { char s [ ] = " abede " ; printf ( " % d STRNEWLINE " , noOfAppends ( s ) ) ; return 0 ; }