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
I'm using my PS4 dual shock controller to connect to the fire stick on the tv so I can play games with it but whenever I try to
Mazyrski [523]
Well i'm not gonna suggest you unpiecing your device because you sir probably lack the skills of doing so but what i will suggest to you is to press your share button and you p playstation button at the same time for at least a minute than try charging it again if that solution does work i would advise tring to unopiece the device but by doing carefully and slowly and remembering where each pieces are staying and i want you to take out the eos system and putting it back in and then piece back together and if that solutiuon doesn't work call playstation or email them or go ahead and go and try to repair it or you can  go and BUY A NEW CONTROLLER. hope i helped have a good day bro.
4 0
3 years ago
What is the definition of Graphic AIDS?.
V125BC [204]

Any image that helps you, the reader, understand the text that the visual aid is accompanied with is referred to as a visual graphic or graphic aid.

Too frequently, readers lazily scan or entirely ignore graphs, diagrams, charts, and tables. Grid graphs, tables, bar charts, flow charts, maps, pie diagrams, and drawings and sketches are the most popular. Relationships are displayed using grid graphs. A visual aid should always be used in conjunction with preparation to interest the audience, improve their comprehension of your message, elicit an emotional response, and assist you in communicating it effectively. Charts, diagrams, graphs, maps, flashcards, posters, images, photos, booklets, folders, pamphlets, cartoons, and comics are examples of graphic aids.

Learn more about graphic here-

brainly.com/question/1169945

#SPJ4

5 0
1 year ago
Design and write a class that implements an ordered list type using a linked list, and a program that exercises and tests the cl
-Dominant- [34]

Answer:

A

Explanation:

7 0
3 years ago
To test for the current date in a query, type ____ in the criteria row of the appropriate column.
lyudmila [28]

Answer:

zxc

Explanation:

zc

6 0
3 years ago
Create a Python program that:
Charra [1.4K]

Answer:

```

file = open("trips.txt","r")

file = file.split("\n")

trip_date = []

fuel_used = []

miles_traveled = []

for i in file:

   trip_date.append(i.split(", ")[0])

for i in file:

   fuel_used.append(i.split(", ")[1])

for i in file:

   miles_traveled.append(i.split(", ")[2])

```

This should put the data in their own lists (i didn't test it) but im not going to solve everything for you. The rest is for you to tinker with. You shouldn't throw your question at us and expect an answer. This is the most that I will give you.

Explanation:

4 0
3 years ago
Other questions:
  • Which occupation requires certification by the state?
    15·2 answers
  • How many fonts are there in a theme?<br> A. 1<br> B. 2<br> C. 4<br> D. 5
    10·1 answer
  • What happens it the offshore team members are not able to participate in the iteration demo due to time zone/infrastructure issu
    11·1 answer
  • ____ are programs that run independently and travel between computers and across networks.
    7·1 answer
  • Software that gives network administrators the ability to provide computer assistance from a central location by allowing them t
    15·1 answer
  • Someone help ASAP! Match the type of information system with its description.
    13·2 answers
  • What is one benefit of using electronic sticky notes ?
    9·2 answers
  • Which computer company was named after an orchard? dell, apple, or ibm
    11·1 answer
  • Multiple arrays. Jump to level 1 For any element in keysList with a value greater than 40, print the corresponding value in item
    7·2 answers
  • How can we style the images and layouts of our pages?
    8·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!