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
hram777 [196]
3 years ago
7

Give a recursive algorithm that takes as input a string s, removes the blank characters and reverses the string. For example, on

input "Hello There", the algorithm should return "erehTolleH". The function IsBlank(c) returns a boolean value indicating whether the character c is the blank character. Your algorithm should not use a loop.
Computers and Technology
1 answer:
Dmitriy789 [7]3 years ago
8 0

Answer:

#include <iostream>

using namespace std;

void recReverse(string exp)

{

if (exp.size() == 0)   //check for empty string

{

 return;

}

if (exp[0] == ' ')

{

 recReverse(exp.substr(1));  //only subtracting, not printing the spaces

}

else

{

 recReverse(exp.substr(1)); //subtracting the previously first element

 cout << exp[0]; //printing new first element

}

}

int main()

{

string exp = "Hello There";

recReverse(exp);

return 0;

}

Explanation:

A recursive function calls itself and works kind of like a loop. A russian doll, if you will. The downside of this program is that if the statement becomes too long it becomes very slow. The upside is, that i some cases, it provides elegant solutions.

In the above code, we have first made sure that we don't have a blank string input. In case we do, we've made sure the function exits before doing any extra work.  Then if the next element of the string is a space, we haven't printed it. Instead we've omitted the 'cout' and carried on with our recursion. Finally, in the else statement, we are printing the character along with subtracting it. Giving us our final recursive call backwards printing.

You might be interested in
Help! ASAP! 1 Question.........°○°​
skelet666 [1.2K]

Answer: I think D)?

Explanation: Or B)

5 0
3 years ago
Balance is the design principle that is represented when using the Crop tool?
RUDIKE [14]

Answer:

The answer is "False".

Explanation:

The rule of thirds implies to the subject, which is not centered mostly on the picture because of new photography formats their shots. Its main object is a little off with one side by using a third-party principle, which draws your attention for the audience into another design, instead of only looking at the center. In another word, we can say that this rule is used as the definition to design the Crop tool to represent as an overlay.

8 0
4 years ago
How many electrons are there in an atom of carbon? A. Four B. Eight C. Six D. One
DochEvi [55]
It's has six electrons because of it's atomic number
5 0
4 years ago
Read 2 more answers
Show the printout of the following code.
alexira [117]

Answer:

E. 7.0

Explanation:

the 7 of the out of the older and make a shame of waves and force of trying

7 0
3 years ago
The appropriate software to use for creating research papers is ________ software. Select one: A. presentation B. word processin
Mademuasel [1]

Answer:

B. word processing

Explanation:

The appropriate software to use for creating research papers is word processing. This refers to any software that is designed with the main function of the production, storage, and manipulation of any kind of text document that is located on a computer or word processor. One of the most popular software example is Microsoft Studio's Word Processor from their Office Software Suite.

4 0
4 years ago
Other questions:
  • Which of the following Internet business models involves a merchant creating an online digital environment that enables people w
    11·1 answer
  • The __________ contains a list of all the resources owned by the library.
    7·1 answer
  • Carmen wanted to clear up space on her computer and remove unwanted files. What would be the best for her to delete?
    6·2 answers
  • __________ describes a module for which the software developer does not care how the processing is performed, but instead, knows
    7·1 answer
  • An expression involving byte, int, and literal numbers is promoted to which of these?
    12·1 answer
  • Find the simple interest Jay owes on a five-year student loan of $48,000 with an annual interest rate of 5%.
    6·1 answer
  • В.
    11·1 answer
  • (b) A mouse is a display device. (c) A monitor is a television.​
    10·1 answer
  • How does beamforming improve network service?
    14·1 answer
  • On a cdma (code division multiple access) network, how are mobile handsets identified by the carrier?
    11·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!