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
Distinguish the functional requirements an engineer would have to specify for a taxi dispatch system.
AveGali [126]
The requirements are mainly written in a feature style notation, using some state charts, context diagrams and other techniques to describe certain parts of the system. See, for example, Software Requirements - Styles and Techniques [Lauesen00].
The functional requirements are divided into four sections. The three modules in figure 1 are developed by separate groups, each responsible for unit testing. All requirements for the taxi, central and communication link component are written in a feature style notation. In addition, a special part of the taxi component is the positioning system. This is dealt with separately since there are special requirements present on this component. The functional requirements consist of four sections: Taxi (3.1), Central (3.2), Communication link (3.3) and Positioning system (3.4). 
6 0
3 years ago
What are the uses of a modem
Vlada [557]

Modem provides internet, WiFi, we can connect multiple devices to internet through modem.

Modem provides radiation of short wavelength and the transmitter in your mobile phones and computers convert those radiations into digital signals and vice-versa.

5 0
3 years ago
In which of the following situations should you expect to provide your Social Security number?
sveta [45]
Hey there!

Some situations you'd need to provide your SSN include when applying for insurance through an insurance company, when applying for a loan or a credit card (or any other company that you're sending a credit application to), banks, investment advisors, and cash transactions over $10,000, such as when buying a car. Also, if you are going to college with financial aid, colleges will collect your SSN. If any other business requests your SSN, they are legally allowed to, however, it's optional. It's also optional when applying for a job at a company, but might affect your chances at getting the job depending on the employer who may want to get credit statistics on their potential employees. 

Hope this helped you out! :-)
7 0
3 years ago
11.5 Code Practice edhesive
Tatiana [17]

Answer:

<html>

<body>

<p style="text-align:center;color:red;">This is a paragraph.</p>

<p><i> "This text is italic</i></p>

</body>

</html>

Explanation:

I got a 75%. Hope this helps.°ω°

8 0
3 years ago
Read 2 more answers
Which tab and group will allow the insertion of rows and columns in a worksheet?
ivanzaharov [21]
Home tab, cells group
5 0
3 years ago
Read 2 more answers
Other questions:
  • It's time for you to schedule a dental checkup. The responsible thing to do is to ___
    11·1 answer
  • How do you take a screenshot on an iPhone?
    8·2 answers
  • What is the term used for the document that describes the scenes and sequence of a game?
    6·1 answer
  • Which two technologies support the building of single-page applications? and are two technologies helpful in building single pag
    12·1 answer
  • The default (preset slide layouts are set up in ____ orientation.
    15·1 answer
  • What are the cues that a website is safe to use for exchanging sensitive information?
    10·1 answer
  • The Curtis Publishing Company's early marketing research efforts mainly had to do with _____. people who drove automobiles peopl
    10·1 answer
  • What is computer code?<br> A. Java Script<br> B. XML<br> C. HTML<br> D. Any programming language
    6·1 answer
  • Which one is better AMD Ryzen 5 Or Nvidia Gtx 2080 ti
    6·1 answer
  • Match the IP Protections Patent, Copyright and Trademark into the following cases:
    12·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!