X344: middleNodeRef3

Consider the following class definition:
   class Link{
      Object data;
      Link next;
   }
List L has a reference to the first node. Write code that returns the reference to the middle node of L. When L has an even number of nodes in the list the "middle node" should be closer to the front (check examples). If there is one node, the code should return that node. Make sure to account for edge cases!

Initial Setup Final Configuration

Examples:

middleRef(Link.CreateList(1,2,3,4)) -> Link.CreateList(2,3,4)
middleRef(Link.CreateList(1,2,3)) -> Link.CreateList(2,3)
Reset
Visualize

Practice a different Java exercise