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
Post a Comment
If you have any doubt ,let me know