Question: Java, LinkedList and Node Write a method stretch that stretches a linked list of integers by a specified integer value amount, so that each node

Java, LinkedList and Node

Write a method stretch that stretches a linked list of integers by a specified integer value amount, so that each node of the list parameter is represented by amount copies of the node in the list that's returned.

The ListNode class will be accessible when your method is tested:

public class ListNode { int info;

ListNode next;

ListNode(int x){ info = x; }

ListNode(int x, ListNode node){

info = x;

next = node; }

}

Skeleton Code Provided:

public class ListStretch { public ListNode stretch (ListNode list, int amount){ // replace statement below with code you write return null; } }

For example

list = [1,2,3] amount = 2 

returns [1,1,2,2,3,3] since each value is represented by two values in the list returned.

list = [] amount = 7 

returns [] since an empty/null list has no nodes that are represented in the return list

list = [5,6,8,9] amount = 4 

returns [5,5,5,5,6,6,6,6,8,8,8,8,9,9,9,9]

Expert Answer

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!