Question
I am still new to Java Language, so please comment out lines so I can understand easily! thank you so much The RecursionP2 class will
I am still new to Java Language, so please comment out lines so I can understand easily! thank you so much
The RecursionP2 class will have only one class level variables: an ArrayList of Integers that will store a data set on which you will be performing different operations using recursive function. All these functions can also be done using iteration, however, you are restricted to only use recursion for full credit. Your program might be randomly checked and any non-recursive approach will be marked down.
The following non-static public methods have to be declared in your class:
-
Constructor (1-arg)
- The constructor will accept in an 1-D array of type int of unknown length and add every element to the class level ArrayList.
-
reverseList(ArrayList)
- The method will accept in an ArrayList of type Integer and return a new ArrayList of type Integer that has all the elements in the reverse order. You are only allowed to use recursion for this method.
-
reverseList()
- The method will use the class level ArrayList and return a new ArrayList of type Integer that has all the elements in the reverse order. You are only allowed to use recursion for this method.
- Hint: This method is a special case of reverseList(ArrayList) and you are allowed to use that method if it helps.
-
toOddList(ArrayList )
- The method will use the class level ArrayList as a parameter and return a new ArrayList of type Integer that contains all the odd indexed numbered elements of the class level ArrayList. You are only allowed to use recursion for this method.
-
toOddList()
- The method will accept in an ArrayList of type Integer and return a new ArrayList of type Integer that contains all the odd indexed numbered elements of the class level ArrayList.
- Hint: This method is a special case of toOddList(ArrayList) and you are allowed to use that method if it helps.
-
toEvenRevList(ArrayList )
- The method will accept in an ArrayList of type Integer as a parameter and return a new ArrayList of type Integer that contains all the even indexed numbered elements of the class level ArrayList in reverse order. You are only allowed to use recursion for this method.
- You can use the reverseList() method as a helper method.
-
toEvenRevList()
- The method will use the class level ArrayList and return a new ArrayList of type Integer that contains all the even indexed numbered elements of the class level ArrayList in reverse order. You are only allowed to use recursion for this method.
- Hint: You can use toEvenRevList(ArrayList) or reverseList(ArrayList) as a helper method.
-
retPenultimate(ArrayList )
- The method will accept in an ArrayList of type Integer and return an int which is the last element of the ArrayList.If the list is empty/null, it should return -1. As usual, you are only allowed to use recursion for this method and the use of reverseList() is prohibited.
-
getList()
- The method would return the class level ArrayList. The return type is ArrayList.
Example
Original: [2, 4, 6, 8, 10] reverseList(): [10, 8, 6, 4, 2] toOddList(): [4, 8] toEvenRevList(): [10, 6, 2] retPenultimate(): 10
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started