Recursive program to print reverse of a given string

Given a string, print it in reverse using recursion.

For example, consider the input string "Techie Delight". The output should be "thgileD eihceT".


As seen in the previous post, we can easily reverse a string using stack data structure. As stack is involved, we can easily modify the code to use function call stack. As recursion finishes, we simply prints the characters stored in the call stack one by one.


Download   Run Code


Download   Run Code


Download   Run Code

The time complexity of above solution is O(n) and total space used is O(n) for function call stack.

Thanks for reading.

Please use ideone or C++ Shell or any other online compiler link to post code in comments.
Like us? Please spread the word and help us grow. Happy coding 🙂

Leave a Reply

Notify of