Repeat Exercise P15.9, but use a queue instead. Data from Exercise P15.9, Use a stack to enumerate

Question:

Repeat Exercise P15.9, but use a queue instead.


Data from Exercise P15.9,

Use a stack to enumerate all permutations of a string. Suppose you want to find all permutations of the string meat. Push the string +meat on the stack. While the stack is not empty Pop off the top of the stack. If that string ends in a + (such as tame+) Remove the + and add the string to the list of permutations. Else Remove each letter in turn from the right of the +. Insert it just before the +. Push the resulting string on the stack. For example, after popping e+mta, you push em+ta, et+ma, and ea+mt.

Fantastic news! We've Found the answer you've been seeking!

Step by Step Answer:

Related Book For  book-img-for-question
Question Posted: