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 was the name of the first computer (machine) language?
Angelina_Jolie [31]

In 1957, the first of the major languages appeared in the form of FORTRAN. Its name stands for FORmula TRANslating system. The language was designed at IBM for scientific computing. The components were very simple, and provided the programmer with low-level access to the computers innards.


8 0
3 years ago
Read 2 more answers
Which of the following statements about professional codes of conduct is true?
Diano4ka-milaya [45]

Answer:

They define how professionals should make decisions about their professional behavior.

Explanation:

3 0
2 years ago
9) If you are working on the part of 5-15 minutes, time-stamping (every 30 seconds) should start at: a) [00:05:00] b) [00:00:00]
loris [4]

Answer:

a) [00:05:00]

Explanation:

Timestamps are markers in a transcript which are used to represent when an event took place. Timestamps are in the format [HH:MM:SS] where HH is used to represent hour, MM to represent the minute and SS to represent the seconds. They are different types of timestamping such as:

i) Periodic time stamps: Occurs at a consistent frequency

ii) Paragraph time stamping: At the beginning of paragraphs

iii) Sentence time stamp: at the beginning of sentence

iv) Speaker time stamp: at change of speaker.

Since a part of 5-15 minutes with time-stamping (every 30 seconds), The time stamping should start at 5 minute [00:05:00] and end at [00:15:00]. This is a periodic time stamp since it occurs every 30 seconds, this means the next time stamp would be [00:05:30] and this continues until 15 minute [00:15:00]

3 0
3 years ago
________ states that the value of a network is equal to the square of the number of users connected to it.
Juliette [100K]

Answer:

This is known as the Metcalfe's Law

Explanation:

In 1980, Metcalfe's law was first presented, not considering users but the communication among compatible devices (e.g. telephone, fax machines and so on). It was after the globalization of the internet that the law got introduced to users and networks.

A demonstration of the law can be seen in fax machines, one fax machine is purposeless, however, the interconnection of multiple fax machines on the network increases the value of every fax machine because the number of the users of the fax machines increases. Similarly, the more the users of a particular service, the more relevant the service becomes.

8 0
3 years ago
Read 2 more answers
Which type of polish grade uses green-colored connectors to help you keep from using the wrong connector type
Anestetic [448]

Answer:

Medium Grade Liquid Metal Polish. pls give me brainliest

8 0
2 years ago
Other questions:
  • Ian is working as a sales manager. He has to generate sales reports using mathematical data that his team has collected. Which c
    15·1 answer
  • A deleted file or folder is not permanently deleted from a computer until which event occurs? The computer is restarted. The Rec
    13·2 answers
  • Sharon is a network engineer for your firm and is investigating the WAN connection into the hot site. In the event of operations
    13·1 answer
  • What feature new to Windows Server 2012 provides the ability to find identical sets of data on a SAN based storage array and red
    14·1 answer
  • A third-grade teacher at Potter Elementary School wants a program that allows a student to enter the amount of money a customer
    14·1 answer
  • Jim is in the market for a car that will last for the next 10 years and has saved up some money for the purpose of a car. What’s
    12·1 answer
  • A USB device used to transfer photos from the memory card to a hard drive is called a _____.
    5·2 answers
  • Question No. 5:
    7·1 answer
  • Write a C++ function with the following signature: void readAndConvert() The function takes no parameters and returns no value.
    6·1 answer
  • Which generation computer supported GUI operating system?​
    11·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!