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 list1
[0, 1, 0] // stored in list2
[0, 1, 2] // stored in list3
and we make the following calls:
list1.surroundWith(1, 4); // surround 1s with 4s
list2.surroundWith(1, 1); // surround 1s with 1s
list3.surroundWith(3, 4); // surround 3s with 4s
then the variables will now store these sequences:
[0, 4, 1, 4, 2, 4, 1, 4] // stored in list1
[0, 1, 1, 1, 0] // stored in list2
[0, 1, 2] // stored in list3
Assume that you are adding this method to the LinkedIntList class as defined below:
public class LinkedIntList {
private ListNode front; // null for an empty list
...
}