Move all occurrence of letter ' x ' from the string s to the end using Recursion | Java program for the 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
import java . util . * ; class Main { public static void rec ( char a [ ] , int i ) { if ( i == 0 ) { System . out . println ( a ) ; return ; } if ( a [ i ] == ' x ' ) { int j = i ; while ( a [ j ] != ' \0' && a [ j + 1 ] != ' \0' ) { char temp = a [ j ] ; a [ j ] = a [ j + 1 ] ; a [ j + 1 ] = temp ; j ++ ; } } rec ( a , i - 1 ) ; } public static void main ( String [ ] args ) { char a [ ] = { ' g ' , ' e ' , ' e ' , ' k ' , ' x ' , ' s ' , ' x ' , ' x ' , ' k ' , ' s ' , ' \0' } ; int n = 10 ; rec ( a , n - 1 ) ; } }