reverseSublist
Category: Arrays
Author: Stuart Reges
Book Chapter: 7.2
Problem: reverseSublist
Write a static method called reverseSublist that takes
as parameters an array of integers and a "from index" (inclusive) and "to
index" (exclusive) and that returns a new array containing the specified
sublist in reverse order. For example, suppose that an array called list
stores the following values:
[0, 1, 2, 3, 4, 5, 6, 7]
and we make the following call:
int[] result = reverseSublist(list, 2, 5);
The sublist specified goes from index 2 (inclusive) to index 5 (exclusive).
In other words, it includes the values [2, 3, 4] from the list. The method
should construct and return a new array that contains this sequence of
values in reverse order:
[4, 3, 2]
This first example used an array of sequential integers, but the array might
contain any values. If the list instead stores these values:
[34, 9, -8, 17, 4, 32, 9]
and we make the following call:
int[] result = reverseSublist(list, 1, 5);
the method should instead return an array containing this sequence:
[4, 17, -8, 9]
You may assume that the two index values are legal:
0