Again, all the levels under it will add their first letters until the string is empty.Īt the top level you have to call it with an empty prefix, because of course, you haven't made any first character choices at this point. So it moves to the next first character, and again, passes all the choices so far down. When we return from the recursion at any level, the current level knows that all the permutations with the current choice of first character have been printed. Since there is nothing more to permute, we can just print what we got. A string permutation is a rearrangement of a set of strings. This way, when we get down to an empty string, the prefix contains a particular series of choices of first letters. These are handed over from the upper levels of the recursion. What your program does is exactly this, but since it wants just to print the permutations, not to collect them, what it does is keep all the choices of first letters done in upper levels of the recursion.
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |