Question: JAVA Help please. Here is an in-place iterative function to reverse an array. * * in-place means: we don't create an extra array (to simplify

JAVA Help please.

Here is an in-place iterative function to reverse an array. * * in-place means: we don't create an extra array (to simplify coding) * */ public static void reverseIterative (int[] a) { int hi = a.length - 1; int lo = 0; while (lo < hi) { int loVal = a[lo]; int hiVal = a[hi]; a[hi] = loVal; a[lo] = hiVal; lo = lo + 1; hi = hi - 1; } } /* * * PROBLEM 2: Convert the above iterative function to a recursive version * * You should write a helper method. You may not use any "fields" to solve * this problem (a field is a variable that is declared "outside" of the * function declaration --- either before or after). * You may not use any other methods * * Your helper function must be parameterized to allow a smaller problem to * be specified. How do you reverse an array of size N? * (the answer is NOT: reverse an array of size N-1 ! ) */ public static void reverseArray (int[] a) { return; // TODO 2 replace this by a call to your recursive helper function, then write the helper function below } // a good place for your helper function for #2

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!