recursive function Simple and URGENT !!

im trying to print all possible sequences of any given 2 strings RECURSIVELY. For example, if i=2 and j=3, i want
the strings

aabbb
ababb
abbab
abbba
baabb
babab
babba
bbaab
bbaba
bbbaa

Can someone help with idea or code ?

beginer92Asked:
Who is Participating?

[Webinar] Streamline your web hosting managementRegister Today

x
 
AndyAinscowConnect With a Mentor Freelance programmer / ConsultantCommented:
For an absolutely clear recursive function it might be better to start with 'aabbb' for example and pass that to a function which moves the first non 'a' with an 'a' to the left of it one position left then calls the function again.  It will stop when it can't swap any more characters

eg.

aabbb
ababb
baabb
....
bbbaa
and now it leaves the recursive function


(What I wrote at first can use recursion but it is really more like a loop)
0
 
beginer92Author Commented:
look, It's a part of the homework and not the complete hw.
I really need help. Pls
0
 
beginer92Author Commented:
can I get a hint of how to think of it recursively. U said an idea is okay
0
 
beginer92Author Commented:
damnn!

i think writting a one line hint should have been a better option than that unfriendly "sorry!"
0
 
AndyAinscowFreelance programmer / ConsultantCommented:
Write 'aabbb'
Find first instance of not 'a' - this is starting point.
Now swap the character at that position with the position before until that not 'a' reaches the start of the string.
Increment initial start point and repeat until start point is at end of string.
0
All Courses

From novice to tech pro — start learning today.