Question: Short Answers Section 9.1 Recursive Functions Write a recursive function with this prototype (using the string type from the new C++ String class): void permute(string

Short Answers Section 9.1 Recursive Functions

Write a recursive function with this prototype (using the string type from the new C++ String class):

 void permute(string first, string second) // Postcondition: The output consists of lines of Strings. Each String // is made by writing some rearrangement of first followed by all // of second. // For example, if first is "CAT" and second is "MAN", then there will // be six lines of output: // CATMAN // ACTMAN // TCAMAN // CTAMAN // ATCMAN // TACMAN 

Hints: The stopping case occurs when the length of first is zero (in which case the function prints second). Some string member functions that will help you for a String s:

s[s.length( ) - 1] is a copy of the last character of s.

s.length( ) is the length of s.

cout << s << endl; will print s.

s = c + s; will insert the character c at the front of s.

s += c; will append the character c to the end of s.

s.erase(0, 1); will remove one character from the front of s.

s.erase(s.length( )-1, 1) will remove the last character from s.

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!