how can all possible combinations of a string or an array of characters be printed.
suppose we have to print all possible combinations of three character a,b,c
.Here's how someone did it
create an array with contents a,b,c,a,b,c ( repeating the characters again).
now print the first three characters a, b,c . Then print three characters , leaving the first character from previous list. So we print b,c,a. Then we print c,a,b. We stop it here and move back from c (not from b).
So we print c , b, a , then b, a ,c then a,c,b and stop. So here they are, the three factorial combinations
abc,bca,cab,bac,acb,cba.

No comments:
Post a Comment