X arrange in last by using recursion

 

// Arrange the all x in last.
//input          : "xxaxiixi";
// output      :  "aiiixxx"
#include<iostream>
#include<string>
using namespace std;
 
  string k(string n)
    {  string ans;
   
    if (n.size()==0)
    {return "";}//this ""sign reveal about string.
     if(n[0]=='x')//in comparing always, use sign '' instead of "".
        { ans=(k(n.substr(1))+'x');}
        else { ans=(n[0]+k(n.substr(1)));}
        return ans;}
int main()
{
 
string b="xxaxiixi";
  k(b);
cout<<k(b);
int i=0;
    return 0;
}

Comments

Popular posts from this blog

Write the program to print all possible words from keypad 2 and 3 from keypad mobile.

Write a program to reverse the string. input = google output = elgoole */

Write the program to make substring of a string.