(Solved) : Zip File File Called Rotatearrayjava Contains Outlines Two Methods Public Static Void Rota Q42786841 . . .

In the zip file there is a file called RotateArray.java thatcontains the outlines of two methods,

public static void rotateRight(int[] a, int n) public static int[] rotateLeft(int[] a, int n)

These are methods that you need to complete. When they arecompleted, you can compile and run the program TestRotate.java andit should produce output exactly like the file test_results.txt

The first method rotateRight() takes as its parameters areference a to an integer array and a positive integer n and it”rotates” the contents of the array to the right n places. So eachelement a[i] of the array should be moved to location a[i+n]. Ifthe index i+n is past the end of the array (that is, i+n >=a.length), then that index should “wrap” back to the beginning ofthe array.

For example, if the input array is a = {1, 2, 3, 4, 5}, thenrotateRight(a, 2) should modify a to contain {4, 5, 1, 2, 3}.

Notice that rotateRight() is a void method since it does notreturn anything. The job of this method is to modify the inputarray. Since the method has a reference to the array, any changesthis method makes to the array are noticed by the method’s caller(you should draw a picture to see why this is true).

Write this method as a two step process. The first step is tocopy the elements of the input array into a new “temporary” array.After everything from the input array has been copied to thetemporary array, then the second step is to copy the contents ofthe temporary array back into the input array but put into theirshifted positions.

The second method rotateLeft() takes in a reference a to aninteger array and a positive integer n and it returns a new arraywhose contents is the contents of the input array rotated to theleft n places. So each element a[i] of the input array should beplaced at location b[i-n]of the returned array. If the index i-n isnegative, then that index should “wrap” around to the end of theoutput array.

For example, if the input array is a = {1, 2, 3, 4, 5}, thenrotateLeft(a, 2) should return an array containing {3, 4, 5, 1,2}.

This method should not make any changes to the input array.

Access to the zip file:http://math.pnw.edu/~rlkraft/cs12300/MW-01/homework/hw8.html

Expert Answer


Answer to In the zip file there is a file called RotateArray.java that contains the outlines of two methods, public static void ro…

Leave a Comment

About

We are the best freelance writing portal. Looking for online writing, editing or proofreading jobs? We have plenty of writing assignments to handle.

Quick Links

Browse Solutions

Place Order

About Us

× How can I help you?