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
A ________ is a material deficiency, or combination of significant deficiencies, that results in more than a remote likelihood t
VLD [36.1K]

Answer:

a.material control failure

Explanation:

A material control failure is a material deficiency, or combination of significant deficiencies, that results in more than a remote likelihood that a material mis-statement in the annual or interim financial statements will not be prevented or detected.

7 0
3 years ago
When you begin typing text, the _________________________ appears on the status bar with an animated pencil writing on paper tha
melomori [17]
Spelling and grammar check icons
3 0
3 years ago
Choose the correct term to complete the sentence.
Andre45 [30]

Answer:

Technology

Explanation:

Edge 2021

8 0
2 years ago
Why is the transmission of information impartial on websites?
Alex777 [14]
I believe that the best answer among the choices provided by the question is <span>B.Websites cannot manage the amount of information they receive. </span>
Hope my answer would be a great help for you.    If you have more questions feel free to ask here at Brainly.
4 0
3 years ago
Read 2 more answers
C program how to input this? ​
Neporo4naja [7]
Chchvjvcuvggiiog. Correct
3 0
2 years ago
Other questions:
  • If in your checkout cart right before you buy something there is an option saying "this order contains a gift." on amazon, what
    7·1 answer
  • What are two advantages of encrypting data stored in the computer system?
    5·1 answer
  • A(n ____ is used to describe the characteristics of data used in a database or other type of computer system.
    12·2 answers
  • Using a single formatting _______ helps to make reading researched information easier; it lets the reader know what to expect.
    7·1 answer
  • kieran wants to search a database quickly for information on the last time a patient came to his medical facility.The informatio
    14·2 answers
  • Importance of type casting in programming ​
    5·1 answer
  • Create a basic program that accomplishes the following requirements: Allows the user to input 2 number , a starting number x and
    12·1 answer
  • What happens when the electrons flowing through the light bulb change direction?
    11·1 answer
  • HELP 100 points
    9·1 answer
  • which filename refers to a 16-bit real-mode program that queries the system for device and configuration data, and then passes i
    5·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!