X340: FindLastNode

Consider the following class definition:
   class Link{
      Object data;
      Link next;
Link objects can be "linked" together to create a structure like this: [1] -> [2] -> [3].

Write a function that takes in a reference to the head of a linked chain that returns the last element in the chain.

For example:
 [1] -> [2] -> [3] would return a reference to the Link object where data=3  [1] -> [2] -> [3] -> [4] -> [5] would return a refernce to the Link object where data=5

Your Answer:


Practice a different Java exercise


Your feedback will appear here when you check your answer.