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
In Tynker, it is not possible to create a/an __________.
xz_007 [3.2K]

Answer:

yes

Explanation:

7 0
3 years ago
Read 2 more answers
A(n) _____ is a local connection point-of-presence that connects a variety of high-performance networks, and its main function i
kirza4 [7]

Answer:

GigaPOP

Explanation:

<em>A gigabit point of presence, also known as GigaPOP is a single entry point to Internet2, which is a high-speed IP network managed by institutions and other organizations. Gigabit Points of Presence generally handle data transmission rates of one gigabit per second or more.</em>

8 0
2 years ago
Which of these is a consistent periodic pulse separated into equivalent intervals of time?
Art [367]
My answer would be B. beat
6 0
3 years ago
Read 2 more answers
What are three good things and three bad things about the metal pewter
Setler79 [48]
Good things:
It is a solid material,NOT plated which makes it easily engravable.
does not tarnish or
discolor easily

Bad things:
It is not a high quality metal
It will melt at low temperatures,so do not get it around extreme heat.
It can damage easy if exposed to acids like lemon juice or vinager


4 0
4 years ago
Ip ____ is the falsification of the source ip address in a packet's header so that it appears to have come from a trusted or leg
tensa zangetsu [6.8K]
<span>IP spoofing the falsification of the source ip address in a packet's header so that it appears to have come from a trusted or legitimate sender.</span>
5 0
3 years ago
Other questions:
  • Can a computer will work more efficiently if you perform disk optimization
    9·1 answer
  • Moore's Law states that the processing power of the latest computer chips doubles about every eighteen months. Assuming the grap
    6·1 answer
  • if you are trying to reduce your debt, which of these expenses should you consider cutting out or cutting back on first?
    11·1 answer
  • Michelle has developed a new program for computers. She later fixed an error found in the program. What is the best way for her
    5·1 answer
  • A year in the modern Gregorian Calendar consists of 365 days. In reality, the earth takes longer to rotate around the sun. To ac
    5·2 answers
  • Universal Containers requires that all users add at least one Product Option from the Maintenance Feature to a bundle.
    5·1 answer
  • Which is a common problem for inserting pictures into placeholders?
    10·1 answer
  • Power point programm<br><br>​
    11·1 answer
  • Write the corresponding Python assignment statements:
    13·1 answer
  • Which two things can a user view in the Reading pane?
    6·2 answers
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!