Check given string is oddly palindrome or not | Set 2 | C # program for the above approach ; Function to check if String formed by odd indices is palindromic or not ; Check if length of OddString odd , to consider edge case ; Push odd index character of first half of str in stack ; Middle element of odd length palindromic String is not compared ; If stack is empty then return true ; Driver Code ; Given String
using System ; using System . Collections . Generic ; class GFG { static bool isOddStringPalindrome ( String str , int n ) { int oddStringSize = n / 2 ; bool lengthOdd = ( ( oddStringSize % 2 == 1 ) ? true : false ) ; Stack < char > s = new Stack < char > ( ) ; int i = 1 ; int c = 0 ; while ( i < n && c < oddStringSize / 2 ) { s . Push ( str [ i ] ) ; i += 2 ; c ++ ; } if ( lengthOdd ) i = i + 2 ; while ( i < n && s . Count > 0 ) { if ( s . Peek ( ) == str [ i ] ) s . Pop ( ) ; else break ; i = i + 2 ; } if ( s . Count == 0 ) return true ; return false ; } public static void Main ( String [ ] args ) { int N = 10 ; String s = " aeafacafae " ; if ( isOddStringPalindrome ( s , N ) ) Console . Write ( " Yes STRNEWLINE " ) ; else Console . Write ( " No STRNEWLINE " ) ; } }