X362: changeHeadNodeValue

Consider the following class definition:
   class Link{
      Object data;
      Link next;
   }
List L has a reference to the first node. Given a reference to a node in a list, make that node the new head and wrap the list around (given 1 2 3 4, with a reference to 3 the list becomes 3 4 1 2). Make sure to account for edge cases!

Initial Setup Final Configuration

Examples:

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

Your Answer:

Reset
Visualize

Practice a different Java exercise

Feedback

Your feedback will appear here when you check your answer.