Question
In java, write a method: public int[] reverse( int[] originalArray ) { }. This method will not change anything in the original/passed array. reverse() returns
In java, write a method: public int[] reverse( int[] originalArray ) { }. This method will not change anything in the original/passed array. reverse() returns an array with the passed array elements reversed. Here is a brief description of what you can do to recursively reverse the passed array. 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
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started