Question: Write a method move that moves a specified number of elements starting from a specified node to the end of the list. Your method should

Write a method move that moves a specified number of elements starting from a specified node to the end of the list. Your method should traverse through the linked list, list, until you find the ListNode which contains the second parameter, remove. The third parameter represents the number of ListNodes to remove after that ListNode and add to the end of the list. Your method should return the transformed linked list.

If no node matching remove is found, then the your method should return the original list.

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 =

Use the skeleton code below:

-------------------------------------------------

public class RemoveN {

public ListNode move(ListNode list, int remove, int n) {

// replace statement below with code you write

return null; } }

---------------------------------------------------------

Examples:

list = [1, 2, 3, 4, 5] remove = 1 n = 3 

returns [1, 5, 2, 3, 4]

The node you're trying to find is 1, and you want to remove the three nodes after it. The nodes you want to remove are [2, 3, 4], so you return [1, 5, 2, 3, 4].

list = [1, 3, 9, 8, 2, 0] remove = 1 n = 5 

returns [1, 3, 9, 8, 2, 0]

The node you're trying to find is 1, and you want to remove the five nodes. There are exactly five nodes after the first node, so the list does not change.

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!