Ask Question
9 October, 03:37

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. 9 October, 04:52
    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?
Get 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 & Technology if there is no answer or all answers are wrong, use a search bar and try to find the answer among similar questions.
Search for Other Answers