Move all occurrence of letter ' x ' from the string s to the end using Recursion | C ++ implementation to Move all occurrence of letter x from the string s to the end using Recursion ; Function to move all ' x ' in the end ; Store current character ; Check if current character is not ' x ' ; recursive function call ; Check if current character is ' x ' ; Driver code
#include <bits/stdc++.h> NEW_LINE using namespace std ; void moveAtEnd ( string s , int i , int l ) { if ( i >= l ) return ; char curr = s [ i ] ; if ( curr != ' x ' ) cout << curr ; moveAtEnd ( s , i + 1 , l ) ; if ( curr == ' x ' ) cout << curr ; return ; } int main ( ) { string s = " geekxsforgexxeksxx " ; int l = s . length ( ) ; moveAtEnd ( s , 0 , l ) ; return 0 ; }