Question: Add a public method reverseOddHalf as described below: Write a method reverseOddHalf that reverses the order of half of the elements of a the ArrayList

Add a public method reverseOddHalf as described below:

Write a method reverseOddHalf that reverses the order of half of the elements of a the ArrayList. Your method should reverse the order of all the elements in odd-numbered positions (position 1, 3, 5, etc.) For example, if the ArrayList originally stores this sequence of numbers when the method is called:

index: 0 1 2 3 4 5 6 7 [1, 8, 7, 2, 9, 18, 12, 0] 

- it should store the following values after the method finishes executing:

index: 0 1 2 3 4 5 6 7 [1, 0, 7, 18, 9, 2, 12, 8] 

Notice that numbers in even positions (positions 0, 2, 4, 6) have not moved. That sub-sequence of numbers is still: (1, 7, 9, 12). But notice that the numbers in odd positions (positions 1, 3, 5, 7) are now in reverse order relative to the original. In other words, the original sub-sequence: (8, 2, 18, 0) - has become: (0, 18, 2, 8).

MUST WORK WITH ALL TYPES OF ARRAYLIST NOT JUST INTEGERS!!!

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!