Ask Question
7 December, 05:51

Write the reverseO function recursively. This function takes a string and the length of the string as arguments and returns the same string with its characters in the reverse order

+1
Answers (1)
  1. 7 December, 06:32
    0
    See the other answer for the solution in Java. However, to make the reversing truly recursive, replace it by this:

    public static String reverseO (String st, int n)

    {

    String ret = st. substring (n-1, n);

    if (n > 1)

    ret + = reverseO (st, n-1);

    return ret;

    }

    Explanation:

    A recursive function calls itself. The function places the last character at the start and then calls itself to do the same on the remainder of the string. Make sure there always is a stop criterium, to end the recursion.

    Recursive functions are often elegant, but most of the times not very efficient in terms of stack usage.
Know the Answer?
Not Sure About the Answer?
Find an answer to your question ✅ “Write the reverseO function recursively. This function takes a string and the length of the string as arguments and returns the same string ...” in 📘 Computers and Technology if you're in doubt about the correctness of the answers or there's no answer, then try to use the smart search and find answers to the similar questions.
Search for Other Answers