Question: JAVA int[] array recursion question: Need to write a method that uses recursion to reverse the elements in an int array public int[] reverse(int[] originalArray)

JAVA int[] array recursion question: Need to write a method that uses recursion to reverse the elements in an int array

public int[] reverse(int[] originalArray) {

}

Method description: The method will copy the first element of the passed array into the last slot of a new array we are building to hold the reverse of the passed array, and copy the last element of the passed array into the first slot of the new array. Then copy the entire middle elements of the passed array into another new array (you need to dynamically create this new array based on the size/number of the middle elements) and recursively reverse these middle elements in this new array. After the recursive call to reverse the middle elements, copy the reversed middle elements that was returned by the recursive call into the middle section of the new reversed array being built. In the end, return this new array that now has all the elements of the passed array reversed. Set up the Base Case(s) and Recursive Case(s). You cant use ArrayLists or other Collection lists. You have to use normal integer arrays.

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!