Answer / Explanation:
Let us define what a Recursion process is before we go ahead to constructing:
Recursion method is a process of solving problems where the solution focus on resolutions to minor or smaller instances of the same problem.
Thus:
public class RecursionP2 {
//constructor
ArrayList<Integer> classList = new ArrayList <Integer> (0);
RecursionP2 (int [] list) {
for(int i = 0; i < list.length; i++) {
classList.add(list [i]);
}
}
public int[] toEvenRevList(int[] list) {
if (list.length == 0) {
i = false;
return new int[0];
}
i = !i;
boolean j = i;
int[] temp = toEvenRevList(Arrays.copyOfRange(list, 1, list.length));
if (j) {
temp = Arrays.copyOf(temp, temp.length + 1);
temp[temp.length - 1] = list[0];
}
return temp;
}
public int[] toEvenRevList() {
return toEvenRevList(ArrayList);
// returns last element
public int retPenultimate(int[] list) {
if (list.length == 1)
return list[0];
return retPenultimate(Arrays.copyOfRange(list, 1, list.length));
}
public int[] getList() {
return ArrayList;
}
On running this, the output below is generated:
RecursionP2(int[] list) {
ArrayList = new int [list.length];
for (int i = 0; i < list.length; i++)
ArrayList[i] = list[i];
}
Consequentially, the reverseList method as public int[] reverseList(int[] list) {
if (list.length == 0)
return new int[0];
int[] value = reverseList(Arrays.copyOfRange(list, 1, list.length));
value = Arrays.copyOf(value, value.length);
value [value.length - 1] = list[0];
return value;
}