← Return

Reverse a Linked ListEasy

This challenge is part of a tutorial track by MyCodeSchool and is accompanied by a video lesson.

Given the pointer to the head node of a linked list, change the next pointers of the nodes so that their order is reversed. The head pointer given may be null meaning that the initial list is empty.

Example

\(head\) references the list \(1 \to 2 \to 3 \to NULL\)

Manipulate the \(next\) pointers of each node in place and return \(head\), now referencing the head of the list \(3 \to 2 \to 1 \to NULL\).