X398: changePointeeDataDirect

Consider the followint class definition

public class Link{
  public Object data;
  public Link next;
}

Notably, there are no getters or setters for this class. You can change a Link's data or next value just by setting them equal to something else.

For this question, the linked chain you will be working with contains 3 links. The first link's data field is '1', the second is '2', and the third is '3'.

The method below takes in two parameters: p refers to the Link with '1' as its data value and 'r' which refers to the link with '3' as its data value.

Use a single assigment to set the info of the Node referred to by p equal to the info of the Node referrerd to by r. You must access this information through r. Do not refer to the character '3' directly.

Here is the initial set up:

and here is the expected final configuration

Your Answer:

Reset
Visualize
Next exercise

Feedback

Your feedback will appear here when you check your answer.