Answered step by step
Verified Expert Solution
Link Copied!

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

image text in transcribed

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 #include 3 using namespace std; 5 void displayPermutations (const string& s) 7 int main() string input; cin >> input; displayPermutations (input); return 0; 10 12 13 14 15 16 17 //Do not modify anything on or above the 1ine below this 18 //YOUR CODE BELOW 19 20 21 22 /YOUR CODE ABOVE 23 //Do not modify anything on or below the line above this 24 25 /YOUR CODE

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Database Design And Relational Theory Normal Forms And All That Jazz

Authors: Chris Date

1st Edition

1449328016, 978-1449328016

More Books

Students also viewed these Databases questions

Question

Explain all drawbacks of the application procedure.

Answered: 1 week ago

Question

Determine Leading or Lagging Power Factor in Python.

Answered: 1 week ago