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
Which of the following is not a data visualization technique?
Minchanka [31]

Answer:

Normalization

Explanation:

From the options given :

Boxplot is a data visualization techniqye used for representing numerical data in the form of a box such that it adequately conveys the five number summary if the dataset which are the minimum, maximum, lower quartile, median and upper quartile, it also depicts the presence of outlines.

Scatter plot are used depict the relationship between two variables on the x and y axis of a graph. Each point is a representation of the (x, y) value pairs of the observation.

Tag clouds are usually used to represent word, metatdata and other free form text using different colors and font sizes to give information about the data.

Normalization is the odd option out as it is used to restructure data in other to promote integrity of data.

3 0
3 years ago
What does the following code do? Assume list is an array of int values, temp is some previously initialized int value, and c is
BigorU [14]

Answer:

Option D is correct.

Explanation:

Option D is correct because  when the condition  if (list[j] < temp) is tested it only gets true when element in list[] array at <em>jth</em> position is less than the value in <em>temp</em> and after that it increments the value of c by this statement: c++ and so c is incremented from 0 to as much times as much elements in list[] are lesser than temp.

6 0
4 years ago
Read 2 more answers
What are the nine tasks (steps) you should perform prior to upgrading a computer to windows 7?
BARSIC [14]
I think those 9 tasks would be :

1. learns windows powershell
2. Plow through licensing
3. focus on strategic improvements
4. Expand the deployment scope
5. Prepare for distributed security
6. Virtualize your destkop
7. Evaluate enterprise features
8. Build compatibility safety nets
9. Remove your users' local admin rights
4 0
4 years ago
Need help with 4.7 lesson practice
-BARSIC- [3]

Answer: Question 1 is A  Question 2 is C

Explanation:

8 0
3 years ago
Where would you go to add fractions to a document in adobe indesign
prisoha [69]

Just select the fraction text and choose Open Type > Fractions from the Character panel menu.

5 0
3 years ago
Other questions:
  • Which of the following is true about a point-and-shoot camera? They always have lenses that you can take on and off. They are of
    8·2 answers
  • Which of the following would an interactive media proffessional must likely need
    9·1 answer
  • What is a tag in an HTML document?
    5·1 answer
  • Which of the following things should you do first when planning your career?
    15·2 answers
  • Convert the following 8­bit binary numbers in two's complement format to decimal (If the number is negative, include the minus s
    5·1 answer
  • A bank has reworked its mortgage application process so that several steps are handled by computer software, and some steps are
    11·1 answer
  • A nursing informatics specialist is preparing an in-service program for staff on healthcare informatics and information technolo
    13·1 answer
  • Does artificial intelligence have a place in our society why or why not
    5·2 answers
  • When connecting past and present issues, it is best to follow a series of steps. Which step is missing from the pattern? 1. Iden
    13·1 answer
  • During the installation of Windows Server 2019 Standard Edition, you encounter a disk that is marked as Disk 0 Unallocated Space
    12·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!