Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

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

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Database Concepts

Authors: David Kroenke

4th Edition

0136086535, 9780136086536

Students also viewed these Databases questions

Question

=+what kinds of policies and practices should be developed?

Answered: 1 week ago

Question

=+ Of the HR issues mentioned in the case,

Answered: 1 week ago