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
What is the way of retrieving information from the Internet?
TEA [102]
We have to search the desired topic on the search box in the homepage
4 0
3 years ago
Read 2 more answers
A.<br>Define a computer with its proper meaning.​
Rashid [163]

Answer:

Computer

Explanation:

a programmable electronic device designed to accept data, perform prescribed mathematical and logical operations at high speed, and display the results of these operations.

7 0
3 years ago
Read 2 more answers
This how to start a brainly challenge besides the default one.
Butoxors [25]

Answer:

thanks for the knowledge! :D

3 0
3 years ago
Read 2 more answers
A(n) _______________ CRM provides all users with the tools and information they need to fit their individual roles and preferenc
fgiga [73]
A(n) "Portal-based" CRM provides all users with the tools and information they need to fit their individual roles and preferences.
4 0
3 years ago
(asking again because point-hogs exist)
yawa3891 [41]

The answer is 2-to-the-power-of-n, since for every input, the number of different combinations doubles. From your list I think answer A is meant to indicate 2ⁿ.

6 0
3 years ago
Other questions:
  • The overall purpose of a food guide is________.
    11·1 answer
  • 2. Consider the two-dimensional array A: int A[][] = new int[100][100]; where A[0][0] is at location 200 in a paged memory syste
    11·1 answer
  • Ken is moving to a new city and considering whether he should rent or buy an apartment. what factors should he consider in his d
    5·1 answer
  • You are going to write a program for Computer test which will read 10 questions from a file, order them randomly and provide the
    11·1 answer
  • A(n) _____ is a firm that delivers a software application, or access to an application, by charging a usage or subscription fee.
    6·1 answer
  • What are the three basic classes of application
    14·2 answers
  • A driver that approaches a controlled intersection with a signal that is not working must:
    12·1 answer
  • Pls help! for computers edge 2021
    7·1 answer
  • What is a motherboard​
    10·1 answer
  • What is the answer ????​
    13·2 answers
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!