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
Please Answer Quickly
leonid [27]

Answer:

graphic design and digital marketing solutions

3 0
3 years ago
Read 2 more answers
Coordination in a global information system requires a _____ architecture for data, standardization within departments.
Phantasy [73]

Coordination in a global information system requires a decentralized architecture for data, standardization within departments

6 0
3 years ago
Does scope frequently changes during a project?<br>​
lesya [120]

Answer:

no

Explanation:

6 0
3 years ago
Read 2 more answers
A group of N stations share a 56-kbps pure ALOHA channel. Each station outputs a 1000-bit frame on average once every 100 sec, e
Sunny_sXe [5.5K]

Explanation:

Here, in the given statement, maximum flow capacity of the ALOHA channel = 18.4% = 0.184

Then, the stations N share 56 kbps

And, the channel rate = 0.184*56 = 10.304 kbps.  

Then, the outputs of the wach stations is 1000-bit frames/100 sec

\therefore, the output of the bits/ sec by each stations = \frac{1000}{100} bits/sec = 10 bits/sec

So, The output of the N stations is 10 bits/sec on the channel that having 10.304kb/sec

Finally, N = \frac{(10.304 \times 10^{3})}{10} = 1030 stations

3 0
3 years ago
You are gong to buy a computer but first you want to do some research to help you select the best model for your needs
DerKrebs [107]

Answer:

Research what kind of computer you want.

Explanation:

I don't know exactly what you are asking here but when doing research you have got to know what you want like how much ram you want, how much storage you want, what brand of computer you want, what core processor you want, and what graphics card you want. You also have to decide if you want a laptop or a full sized desk top computer.

8 0
3 years ago
Other questions:
  • Identify requirements that should be considered when determining the locations and features of firewalls. What are some importan
    5·1 answer
  • What is a new ransomware program that encrypts your personal files and demands payment for the files' decryption keys? Multiple
    10·1 answer
  • Within the sites that support disaster recovery, __________ is a separate facility that does not have any computer equipment but
    7·1 answer
  • Write the proghrams for the following:
    13·1 answer
  • Define additional characteristics such as font weight or style for an html tag
    5·1 answer
  • Need help with this
    13·1 answer
  • Why are computers complicated?
    15·1 answer
  • Which of these organs is not found in the excretory system
    7·2 answers
  • Which control program flow options runs to the end of the code block and resumes the break mode at the statement that follows?
    12·1 answer
  • Jobs that use math and science to solve problems involving the design and development of technologies can be found in the what c
    13·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!