I am trying to learn recursivity and I am trying to do a program that given a list of words it returns them in a reversed order.
Example:
imput: house tree car
output: car tree house
Now I have some doubts about recursivity: I read the c++ thread about recursivity and it sais that the point of recursivity is to express the cases in function of a simpler case until we get to the base case whose value we know.
Now the thing is, do we even have a base case here? I mean, we don't even know how much words will be entered.
Secondly, how can we express a case in function of a simpler one?
Look for spaces and reverse the string according to spaces rather than by character as in Josue Molina's example. He/she's trying to give you the general structure without the answer.
You're going to need the find and substr methods in the string class. If there are no more spaces, then there are no more words. Just follow Josue Molina's example after you figure out how to get the first word, but backwards.
I don't think a recursive approach would be the best for this problem.
What you can do is split the string into tokens that are then stored in a container. Finally, you display the contents of the container in reverse order. Here's a quick example: http://ideone.com/L60EI2
Nevertheless, it's still doable. Just follow GRex2595's instruction.