Question
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
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]
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