1answer.
Ask question
Login Signup
Ask question
All categories
  • English
  • Mathematics
  • Social Studies
  • Business
  • History
  • Health
  • Geography
  • Biology
  • Physics
  • Chemistry
  • Computers and Technology
  • Arts
  • World Languages
  • Spanish
  • French
  • German
  • Advanced Placement (AP)
  • SAT
  • Medicine
  • Law
  • Engineering
miss Akunina [59]
3 years ago
10

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
Computers and Technology
2 answers:
Leviafan [203]3 years ago
8 0

Answer:

C++.

Explanation:

#include <iostream>

#include <iterator>

using namespace std;

/////////////////////////////////////////////////

class RecursionP2 {

   int array_size, count;

   int array_list[8];

public:

   RecursionP2(int array_list[], int array_size) {

       this->array_size = array_size;

       count = 0;

       

       for (int i = 0; i < array_size; i++) {

           this->array_list[i] = array_list[i];

       }

   }

   /////////////////////////////////////////////

   void reverseList(int array_list[], int size) {

       if (size <= 1)

           return;

       else {

           int temp;

           temp = array_list[0];

           array_list[0] = array_list[size-1];

           array_list[size-1] = temp;

           return reverseList(array_list+1, size-2);

       }

   }

   

   void reverseList() {

       this->reverseList(array_list, array_size);

       

       cout<<"{";

       for (int i = 0; i < array_size-1; i++) {

           cout<<array_list[i]<<", ";

       }

       cout<<array_list[array_size-1]<<"}";

       

   }

   /////////////////////////////////////////////

   void oddList(int array_list[], int index) {

       if (index >= array_size)

           return;

       else {

           int temp = array_list[index];

           array_list[index] = array_list[count];

           array_list[count] = temp;

           count = count + 1;

           return oddList(array_list, index+2);

       }

   }

   

   void oddList() {

       this->oddList(array_list, 1);

       

       cout<<"{";

       for (int i = 0; i < count-1; i++) {

           cout<<array_list[i]<<", ";

       }

       cout<<array_list[count-1]<<"}";

       

   }

   /////////////////////////////////////////////

   void evenRevList(int array_list[], int index) {

       if (index >= array_size)

           return;

       else {

           int temp = array_list[index];

           array_list[index] = array_list[count];

           array_list[count] = temp;

           count = count + 1;

           return oddList(array_list, index+2);

       }

   }

   

   void evenRevList() {

       this->evenRevList(array_list, 0);

       this->reverseList(array_list, count);

       

       cout<<"{";

       for (int i = 0; i < count-1; i++) {

           cout<<array_list[i]<<", ";

       }

       cout<<array_list[count-1]<<"}";

       

   }

   /////////////////////////////////////////////

   int retPenultimate(int array_list[], int size) {

       if (size < 1) {

           return -1;

       }

       else if (size == 1) {

           return array_list[0];

       }

       else {

           return retPenultimate(array_list+1, size-1);

       }

   }

   /////////////////////////////////////////////

   int* getList() {

       return array_list;

   }

};

/////////////////////////////////////////////////

int main() {

   int array_list[] = {2, 4, 6, 8, 10, 12 ,4, 1};

   int array_size = distance(begin(array_list), end(array_list));

   RecursionP2 recursionp2_1(array_list, array_size);

   /////////////////////////////////////////////

   //recursionp2_1.reverseList();

   //recursionp2_1.oddList();

   //recursionp2_1.evenRevList();

   cout<<recursionp2_1.retPenultimate(array_list, array_size);

   /////////////////////////////////////////////

   return 0;

}

Aliun [14]3 years ago
4 0

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;

   }

You might be interested in
Write down a pair of integers whose sum is​ 0
Tems11 [23]

Answer:

-1 ans +2 are the pair of integers whose sum is 0.

3 0
3 years ago
A programmer wrote the program below. The program uses a list of numbers called numList. The program is intended to display the
Nezavi [6.7K]

Answer:

The conclusion is incorrect; using the test case [0, 1, 4, 5] is not sufficient to conclude the program is correct.

Explanation:

From the code snippet given, we cannot conclude that the test case is sufficient.

One of the reasons is because the test case contains only integer variables.

Tests need to be carried out for other large and floating points numerical data types such as decimal, double, float, etc. except that when it's known that the inputs will be of type integer only else, we can't rush into any conclusion about the code snippet

Another reason is that input are not gotten at runtime. Input gotten from runtime environment makes the program flexible enough.

Lastly, the array length of the array in the code segment is limited to 4. Flexible length needs to be tested before we can arrive at a reasonable conclusion.

8 0
4 years ago
Who wants to play kahoot.it and the pin is 7385096
nadezda [96]

meeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeee

3 0
3 years ago
Read 2 more answers
Not a subject question but please help
Doss [256]

Answer:

You go to account settings, edit your profile and click preferences and then go to choose level and put which grade u are in the options r middle school, high school, and college

Explanation:

8 0
3 years ago
Read 2 more answers
To which built-in object does the function sin(x) belong?
Harlamova29_29 [7]
Choice B

Explanation: Sin() is a math function.
5 0
4 years ago
Other questions:
  • Computers have become easier to use and more powerful over time.
    12·2 answers
  • What is the purpose of citations?
    13·1 answer
  • Direct Mapped Cache. Memory is byte addressable. Fill in the missing fields based upon the properties of a direct-mapped cache.
    6·1 answer
  • What is different between a pc mouse and a real mouse
    12·2 answers
  • According to your text, three factors are responsible for the rapid rise in new product development. They are faster and more ec
    9·1 answer
  • A router is a peripheral that may need troubleshooting if the network goes down.
    12·2 answers
  • A weighted GPA counts__more highly.
    12·1 answer
  • Every modern nation has a Central Bank. Which of the following is the Central Bank for these United States?
    14·2 answers
  • In a program you need to store identification numbers of 5 employees and their weekly gross pay.
    11·1 answer
  • Why key logger are essential for computer system
    14·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!