Answered step by step
Verified Expert Solution
Question
1 Approved Answer
String Permutations Write a function void displayPermutations(const string&s); that prints out every permutation of a given string separated with a space Input of cab would
String Permutations Write a function void displayPermutations(const string&s); that prints out every permutation of a given string separated with a space Input of "cab" would produce: cab cba acb abc bca bac Hints: You will want a recursive helper that looks like: void displayPermutations(const string&unusedChars, const string& usedChars). The parameter unusedChars will have the letters left to use and usedChars will have those already used in the current string you are building. Your first call would be something like (cab", ) If there are no more letters left to use, you have an answer you can print out. Otherwise, you need to make a recursive call for each of the possible letters you could add to the string you are building. ("cab","") should result in calls using ("ab",-c"), ("cb", "a") and ("ca",-b"). A call with ("ab", "c") would turn into calls with ("b", "ca") and ("a", "cb") You can use a for loop inside your helper function... you can do this purely recursively, but a version with a loop is easier to understand Code: 1 #include
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started