String formed with middle character of every right substring followed by left sequentially | C ++ implementation of the above approach ; Function to decrypt and print the new string ; If the whole string has been traversed ; To calculate middle index of the string ; Print the character at middle index ; Recursively call for right - substring ; Recursive call for left - substring ; Driver Code
#include <iostream> NEW_LINE using namespace std ; void decrypt ( string Str , int Start , int End ) { if ( Start > End ) { return ; } int mid = ( Start + End ) >> 1 ; cout << Str [ mid ] ; decrypt ( Str , mid + 1 , End ) ; decrypt ( Str , Start , mid - 1 ) ; } int main ( ) { int N = 4 ; string Str = " abcd " ; decrypt ( Str , 0 , N - 1 ) ; cout << " STRNEWLINE " ; N = 6 ; Str = " gyuitp " ; decrypt ( Str , 0 , N - 1 ) ; return 0 ; }