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
Sequential codes may be used to represent complex items or events involving two or more pieces of related data.
katrin2010 [14]

Answer:

The answer is "Option B".

Explanation:

Sequential codes are modules that work toward the solution of a problem that is arranged in a serialized manner. It is also known as serial codes, It is code in which the following two digits differ by a single digit in the binary representation.

  • It helps to decide, which task and how long it will take.
  • It uses communication to provide synchronized and shares resources between tasks.
4 0
3 years ago
Analyzing Uses for PDFs
Sauron [17]

Answer:

You need to send a file to someone who does not have Word

Explanation:

In this case the answer is You need to send a file to someone who does not have Word.

But we use PDF to send files without changing its format.

4 0
3 years ago
The shortest compressed format of the ipv6 address 2001:0db8:0000:1470:0000:0000:0000:0200 is
devlian [24]

The answer is : 2001:DB80:1470::200

A double colon ( :: ) can replace any single, contiguous string of one or more 16-bit segments (hextets) which is  consist of all 0s, and it can only be used once per IPv6 address. Therefore,any leading 0s (zeros) in any 16-bit section or hextet can be omitted.

3 0
3 years ago
Write a query to show the price reduced by 10% for all products that are tables or entertainment centers with a standard price g
IceJOKER [234]

Answer:

Below is the required code:

Explanation:

SELECT Product_Finish AS "Desk Finish",

avg(Standard_Price) AS "Average Price"

FROM Product_T

WHERE "Average Price">200

ORDER BY "Average Price" DESC;

8 0
3 years ago
You work in an office that uses Linux servers and Windows servers. The network uses both the TCP/IP protocol. The Linux server i
kap26 [50]

Answer:

The answer is "ifconfig".

Explanation:

The ifconfig. me is indeed a website that shows basic network packets, like IP address, hostname, user agent string. It provides a simple interface that may be queried with the assistance of the command prompt to obtain the required information. The whole function provides the essential information about a certain program's interface.

5 0
3 years ago
Other questions:
  • Which of the following are you likely to find between multiple school buildings in a city wide school district?
    9·1 answer
  • Forms often allow a user to enter an integer. Write a program that takes in a string representing an integer as input, and outpu
    9·1 answer
  • Describe how computer is in the last 35 years
    6·1 answer
  • Idea citizen activation
    9·2 answers
  • 8.13 LAB: Elements in a range Write a program that first gets a list of integers from input. That list is followed by two more i
    8·1 answer
  • Persuasion is when Someone speaks to crowd about love <br>○True<br>○False​
    10·1 answer
  • The best way to safeguard your document is to save it
    11·1 answer
  • What are other ways you could use the shake or compass code blocks in physical computing projects?
    14·1 answer
  • Select the correct answer from each drop-down menu. A company is recruiting for a web designer. What kind of candidate should th
    14·2 answers
  • If you walked into a room containing three computers and were told one of them was infected with malware, how would you determin
    10·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!