Question: Write a method called surroundWith that takes an integer x and an integer y as parameters and surrounds all nodes in the list containing the

Write a method called surroundWith that takes an integer x and an integer y as parameters and surrounds all nodes in the list containing the value x with new nodes containing the value y. In particular, each node that contains the value x as data should have a new node just before it and just after it that each contain the value y. If no nodes in the list contain the value x, then the list should not be modified. For example, suppose that the variables list1, list2, and list3 store the following sequences of values:

[0, 1, 2, 1] // stored in listl ГО, 1, 0] // stored in list2 [0, 1, 2] // stored in list3

and we make the following calls:

[0, 1, 2, 1] // stored in listl , 1, 0] //

then the variables will now store these sequences:

stored in list2 [0, 1, 2] // stored in list3

[0, 1, 2, 1] // stored in listl , 1, 0] // stored in list2 [0, 1, 2] // stored in list3

Step by Step Solution

3.50 Rating (157 Votes )

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock

public void surroundWith int x int y if front null return taget ListNode c... View full answer

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 Building Java Programs A Back to Basics Approach Questions!