X358: reverseUptoRef11

Consider the following class definition:
   class Link{
      Object data;
      Link next;
   }
p is a reference to the first node in list L. Integer val is the value of a node in L. You would reverse the list upto the node (the node containing val) if there was one. Make sure to account for edge cases! If the Integer parameter is null or doesn't exist then don't change the list.

Initial Setup Final Configuration

Examples:

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

Your Answer:

Reset
Visualize

Practice a different Java exercise

Feedback

Your feedback will appear here when you check your answer.