203.23.149.162 writes:
how do i write code for a recursive solution to print the permutations of characters in a string assuming no repeated characters.
202.54.7.12 writes:
Hi,
i can understand permutations of chars in a string. i might be of help if u could clearly explain 'recursive solutions'...
ganesh
194.158.187.242 writes:
Do you mean reverse sequence with 'permutation', ie change 'abc' into 'cba'?
If you do, you can write a method that says
the permutation of a string is:
the permutation of the substring from character 2 onwards (the recursion)
+ the first character.
e.g. 'abc'
-> permutated('abc')
-> permutated('bc') + 'a'
-> (permutated('c') + 'b') + 'a',
-> ((permutated('') + 'c') + 'b') + 'a'
-> '' + 'c' + 'b' + 'a'
-> 'cba'
Voila. Be carefull to end recursion when there are no chars left.
Henk Jan
202.54.7.8 writes:
Hi,
actually, if u are looking at reversing a string StringBuffer class does it for u..
Ganesh