Solved

recursive function Simple and URGENT !!

Posted on 2006-10-22
9
189 Views
Last Modified: 2013-11-20
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 ?

0
Comment
Question by:beginer92
  • 3
  • 2
9 Comments
 

Author Comment

by:beginer92
Comment Utility
look, It's a part of the homework and not the complete hw.
I really need help. Pls
0
 

Author Comment

by:beginer92
Comment Utility
can I get a hint of how to think of it recursively. U said an idea is okay
0
 

Author Comment

by:beginer92
Comment Utility
damnn!

i think writting a one line hint should have been a better option than that unfriendly "sorry!"
0
 
LVL 44

Expert Comment

by:AndyAinscow
Comment Utility
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
 
LVL 44

Accepted Solution

by:
AndyAinscow earned 500 total points
Comment Utility
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

Featured Post

Enabling OSINT in Activity Based Intelligence

Activity based intelligence (ABI) requires access to all available sources of data. Recorded Future allows analysts to observe structured data on the open, deep, and dark web.

Join & Write a Comment

Suggested Solutions

Introduction: Dynamic window placements and drawing on a form, simple usage of windows registry as a storage place for information. Continuing from the first article about sudoku.  There we have designed the application and put a lot of user int…
Introduction: Load and Save to file, Document-View interaction inside the SDI. Continuing from the second article about sudoku.   Open the project in visual studio. From the class view select CSudokuDoc and double click to open the header …
This video will show you how to get GIT to work in Eclipse.   It will walk you through how to install the EGit plugin in eclipse and how to checkout an existing repository.
In this seventh video of the Xpdf series, we discuss and demonstrate the PDFfonts utility, which lists all the fonts used in a PDF file. It does this via a command line interface, making it suitable for use in programs, scripts, batch files — any pl…

763 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

13 Experts available now in Live!

Get 1:1 Help Now