Ask Question

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

+3
Answers (1)
  1. Today, 21:36
    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 & Technology if the answers seem to be not correct or there’s no answer. Try a smart search to find answers to similar questions.
Search for Other Answers