You are required to solve the Move Tail to Head problem in a linked list. In this exercise, you are supposed to move the tail (or last) node in a singly linked list to the front of the linked list so that it becomes the new head of the linked list.
For example, in the illustration below, the tail node (D) moves to the start of the linked list and replaces the head node (A).
Singly Linked List: Move Tail to Head
HEAD
TAIL
1 of 2
Coding Time!
In the code below, the move_tail_to_head is a class method of the LinkedList class. You cannot see the rest of the code as it is hidden. As move_tail_to_head is a class method, please make sure that you don’t change the indentation of the code provided to you. You are required to write your solution under the method prototype.
For this exercise, you are not required to return anything from the method. Just modify the linked list so that the tail node is moved to the head node, the previous head node shifts ahead, and the tail node is updated to point to None. Remove the pass statement if you start implementing your solution.