X631: firstNodeEqualsValue

Consider the following class definition:
   class Link{
      Object data;
      Link next;
   }
List L has a reference p to the first node. Write code that returns a reference to the node before the first node in the chain that equals to a given parameter (otherwise return null) - could do this with a look ahead or runner technique. Make sure to account for edge cases!

Initial Setup Final Configuration

Examples:

refFirstNodeWithValue(Link.CreateList(4,3,2),3) -> Link.CreateList(4,3,2)

Your Answer:

Reset
Visualize

Feedback

Your feedback will appear here when you check your answer.