There may be an error with the code. Answer the following: 1) Design your own linked list of 4 nodes with different values 2) If the code has an error, describe the issue and provide an example of calling the update function with values of your choice and show what the linked list looks like a. Also, show the code changes you would make to fix the error 3) If the code does not have an error, provide an example of calling the update function with values of your choice and show what the linked list looks like For example, if your linked list was 1 -> 2 -> 3 -> 4, and you think there is an error with this code, you could say something like “the problem with the code is xxx and after calling update(3, 5), the linked list will look like (and then show your linked list)” If you think the code does not have an error, still provide an example of calling update with your own values and show what the linked list ends up looking like
Exercise 2
Given the following function to update a node in a standard linked list:
public boolean update(Node head, int oldValue, int newValue)
{
if (head == null)
return false;
while (head != null)
if (head.data == oldValue)
{
head.data = newValue;
return true;
}
else
head = head.next;
return false;
}
There may be an error with the code. Answer the following:
1) Design your own linked list of 4 nodes with different values
2) If the code has an error, describe the issue and provide an example of calling the
update function with values of your choice and show what the linked list looks like
a. Also, show the code changes you would make to fix the error
3) If the code does not have an error, provide an example of calling the update function
with values of your choice and show what the linked list looks like
For example, if your linked list was 1 -> 2 -> 3 -> 4, and you think there is an error with
this code, you could say something like “the problem with the code is xxx and after calling
update(3, 5), the linked list will look like (and then show your linked list)”
If you think the code does not have an error, still provide an example of calling update with
your own values and show what the linked list ends up looking like
Step by step
Solved in 2 steps with 1 images