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
Could anyone please answer this?
Anastaziya [24]

Answer:

D

Explanation:

The answer is D because if you're looking for lightweight materials, you'll be dealing with chemistry, and chemistry is sience.

4 0
2 years ago
You want to make it possible for your smartphone to share its internet access wirelessly with your friends device which of the f
IrinaVladis [17]

Answer:WiFi or hotspots

Explanation:you will have to turn on your WiFi or hotspots on your smart phone and allow your friend to also turn his WiFi or hotspot after you will search for your WiFi and connect there he can use the internet

6 0
3 years ago
Which of the following is true about occupations within the STEM fields? Many occupations use mathematics, even if it is not the
Kazeer [188]

Answer:

Many occupations use mathematics, even if it is not the primary focus of a given job.

Explanation:

Think about software developers, they develop apps, websites, and other things, but they also use math in the process. Scientists use statistics. Mechanics use math to make sure their measurements are right. Therefore, I think your best bet would be

A. Many occupations use mathematics, even if it not the primary focus of a given job.

8 0
3 years ago
Read 2 more answers
Shadow and highlight create depth (3D).<br> TRUE OR FALSE
tamaranim1 [39]

Answer:

true because then it would be like not popping out

7 0
2 years ago
Which is the another name of automatic sequence control calculator​
Alla [95]

Answer:

IBM Automatic Sequence Controlled Calculator (ASCC)

3 0
2 years ago
Other questions:
  • What car dealership websites did you use to conduct your research?​
    8·1 answer
  • . Dеclarе a onе-dimеnsional array of 30 doublеs (on thе stack) namеd rainfall
    11·1 answer
  • Which of the following provides astronomical evidence for the age of the earth?
    11·1 answer
  • A group of computers that are interconnected in order to share information or documents is called a _____.
    7·1 answer
  • Whats the wire that connects to the wifi box
    15·2 answers
  • Panes created using the vertical split bar scroll together horizontally. true or false.
    12·1 answer
  • Exchanging which type of data uses the least bandwidth?
    7·2 answers
  • Alexandria works for a non-profit company that asks for donations to help the homeless people in her community. Recently the dat
    12·1 answer
  • Do small companies need computers? why?<br>​
    12·1 answer
  • What will be the output, if any, when the user clicks the right mouse button?
    5·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!