Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

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

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Intranet And Web Databases For Dummies

Authors: Paul Litwin

1st Edition

0764502212, 9780764502217

Students also viewed these Databases questions

Question

Describe the nature of negative messages.

Answered: 1 week ago