Perfect reversible string | C ++ program to check if a string is perfect reversible or nor ; This function basically checks if string is palindrome or not ; iterate from left and right ; Driver program to run the case
#include <bits/stdc++.h> NEW_LINE using namespace std ; bool isReversible ( string str ) { int i = 0 , j = str . length ( ) - 1 ; while ( i < j ) { if ( str [ i ] != str [ j ] ) return false ; i ++ ; j -- ; } return true ; } int main ( ) { string str = " aba " ; if ( isReversible ( str ) ) cout << " YES " ; else cout << " NO " ; return 0 ; }