Write a method called surroundWith that takes an integer x and an integer y as parameters and

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 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:

then the variables will now store these sequences:

Fantastic news! We've Found the answer you've been seeking!

Step by Step Answer:

Related Book For  book-img-for-question
Question Posted: