1answer.
Ask question
Login Signup
Ask question
All categories
  • English
  • Mathematics
  • Social Studies
  • Business
  • History
  • Health
  • Geography
  • Biology
  • Physics
  • Chemistry
  • Computers and Technology
  • Arts
  • World Languages
  • Spanish
  • French
  • German
  • Advanced Placement (AP)
  • SAT
  • Medicine
  • Law
  • Engineering
Vikentia [17]
3 years ago
14

Write the routines with the following declarations: void permute( const string & str ); void permute( const string & str

, int low, int high ); The first routine is a driver that calls the second and prints all the permutations of the characters in string str. If str is "abc", then the strings that are output are abc, acb, bac, bca, cab, and cba. Use recursion for the second routine.
Computers and Technology
1 answer:
fomenos3 years ago
5 0

Answer:

Here is the first routine:

void permute( const string &str ) {  // function with one parameter

 int low = 0;

 int high = str.length();

 permute(str, low, high);

}    

Or you can directly call it as:

 permute(str, 0, str.length());

Explanation:

The second routine:

void permute( const string &str, int low, int high)  

//function with three parameters

{ string str1 = str;

 if ( low == high ) {  //base case when last index is reached

   for (int i = 0; i <= high; ++i)

     cout << str1[i]; }  //print the strings  

 else {

   for (int i=low; i<high; ++i) {  // if base case is not reached

     string temp = str1;   //fix a character

     swap( str1[i], str1[low] ); //swap the values

     permute( str1, low + 1, high );  //calling recursive function (recursion case)

     swap( str1[i], str1[low] );     }  } } //swap again to go to previous position

In this function the following steps are implemented:

A character is fixed in the first position.

Rest of the characters are swapped with first character.

Now call the function which recursively repeats this for the rest of the characters.

Swap again to go to previous position, call the recursive function again and continue this process to get all permutations and stop when base condition is reached i.e. last index is reached such that high==low which means both the high and low indices are equal.

You can write a main() function to execute these functions.

int main() {

 string str;

 cout << "Enter a string: ";

 cin >> str;

 permute(str);  }

You might be interested in
An incident response plan should be created be for a software system is released for use.
Nat2105 [25]
The answer is choice “a. True”.
8 0
1 year ago
Why doesnt brainly let me skip by watching video?
oksian1 [2.3K]

What do you want to skip in brainly? There isn't anything to skip that I can think of.

4 0
3 years ago
Explain what qualifies a device to be called a computerized system​
Karolina [17]

Answer; A peripheral is a “device that is used to put information into or get information out of the computer.”[1]

There are three different types of peripherals:

Input, used to interact with, or send data to the computer (mouse, keyboards, etc.)

Output, which provides output to the user from the computer (monitors, printers, etc.)

Storage, which stores data processed by the computer (hard drives, flash drives, etc.)

Explanation:

7 0
3 years ago
How is binary number related to real number?
Bogdan [553]

Answer:

.....................????..?..

7 0
2 years ago
Read 2 more answers
Distinguish between weighted codes and non weighted codes​
Gnom [1K]

Answer:

In weighted codes, each digit is a assigned a specific weight according to its position. NON- WEIGHTED CODE - The Non - Weighted Code are not positionally weighted. In other words, codes that are not assigned with any weight to each digit position. Hope it helpful U.

8 0
2 years ago
Other questions:
  • Select the correct answer.
    6·1 answer
  • Magnetic ram (mram) uses ____ rather than an electrical charge to store data.
    6·1 answer
  • o maintain reasonable key security (mark all that apply): Ensure that someone else always has an extra key. Ensure that no extra
    10·1 answer
  • Write a subclass named 'ReadWrite' with the following additional behavior: Any necessary constructors. a method named 'setVal' t
    9·1 answer
  • Name three types of data stored on a computer’s hard disk
    11·1 answer
  • The main purpose of a honeypot is Select one:
    12·1 answer
  • • Suppose an application generates chunks of 40 bytes of data every 20 msec, and each chunk gets encapsulated in a TCP segment a
    5·1 answer
  • How does polymorphism enable you to program "in the general" rather than "in the specific"? Discuss the key advantages of progra
    11·1 answer
  • What is the result of the following code?<br><br> x=7//2+10%2**4<br><br> print(x)
    15·1 answer
  • What instructions would a computer have the hardest time completing correctly
    12·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!