Move all occurrence of letter ' x ' from the string s to the end using Recursion | C ++ program for above approach ; Recursive program to bring ' x ' to the end ; When the string is completed from reverse direction end of recursion ; If the character x is found ; Transverse the whole string ; Swap the x so that it moves to the last ; call to the smaller problem now ; Driver Code ; Size of a ; Call to rec
#include <bits/stdc++.h> NEW_LINE using namespace std ; void rec ( char * a , int i ) { if ( i == 0 ) { cout << a << endl ; return ; } if ( a [ i ] == ' x ' ) { int j = i ; while ( a [ j ] != ' \0' && a [ j + 1 ] != ' \0' ) { swap ( a [ j ] , a [ j + 1 ] ) ; j ++ ; } } rec ( a , i - 1 ) ; } int main ( ) { char a [ ] = { ' g ' , ' e ' , ' e ' , ' k ' , ' x ' , ' s ' , ' x ' , ' x ' , ' k ' , ' s ' , ' \0' } ; int n = 10 ; rec ( a , n - 1 ) ; }