Question: Below is the code for the LinkedIntList class that you had for homework 7 . Finish defining the doubleUp method using recursion by writing the

Below is the code for the LinkedIntList class that you had for homework 7. Finish defining the doubleUp method using recursion by writing the code that belongs between the braces for the recursive helper method doubleUpH. The doubleUp method creates a new list that is twice as long and that looks like the original list but with every entry appearing twice in a row (duplicated) while leaving the original list unchanged. For example, if list contained the numbers 5,1,1,5,2,3 then list.doubleUp(), would create and return a new list that contained 5,5,1,1,1,1,5,5,2,2,3,3 and the original list would still have the numbers 5,1,1,5,2,3. The only method your code may call is doubleUpH itself and your code must not contain any loops. Solutions that violate either of these restrictions will receive 0 points. Your new code should be completely contained inside the body of the doubleUpH method. If your solution changes the arguments to the doubleUpH method or changes the public doubleUp method, you will receive at most 10 out of the 20 points.
public class LinkedIntList {
private class Node {
private int item;
private Node next;
public Node(){}
public Node(int number, Node nextNode){
item = number;
next = nextNode;
}
}
private Node first; // first node of the list
public LinkedIntList(){
first = null;
}
/* Other LinkedIntList methods not listed here for the sake of space */
public LinkedIntList doubleUp(){
LinkedIntList answer = new LinkedIntList();
answer.first = doubleUpH(first);
return answer;
}
private Node doubleUpH(Node front)
// WRITE YOUR CODE HERE
}
}

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!