X627: addNodeAfterRef7

Consider the following class definition:
   class Link{
      Object data;
      Link next;
   }
p is a reference to the first node in a List L. Create a new node and add the given integer parameter as its data. Insert the new node after the node pointed to by ref. Make sure to account for edge cases! If p AND parameter are null, point p to integer param data. If the reference parameter is null then prepend the integer parameter to the list.

Initial Setup Final Configuration

Examples:

addNodeAfterRef(Link.CreateList(1,2,3,4),2,9) -> Link.CreateList(1,2,9,3,4)

Your Answer:

Reset
Visualize

Practice a different Java exercise

Feedback

Your feedback will appear here when you check your answer.