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](https://dsd5zvtm8ll6.cloudfront.net/si.question.images/images/question_images/1607/4/0/3/1625fcf069a7bf1e1607403162169.jpg)
and we make the following calls:
![[0, 1, 2, 1] // stored in listl , 1, 0] //](https://dsd5zvtm8ll6.cloudfront.net/si.question.images/images/question_images/1607/4/0/3/1795fcf06ab584cc1607403178883.jpg)
then the variables will now store these sequences:
![stored in list2 [0, 1, 2] // stored in list3](https://dsd5zvtm8ll6.cloudfront.net/si.question.images/images/question_images/1607/4/0/3/1915fcf06b7bb5941607403191977.jpg)
[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
public void surroundWith int x int y if front null return taget ListNode c... View full answer
Get step-by-step solutions from verified subject matter experts
