https://leetcode.com/problems/reverse-linked-list/
- As the list is singly list, we must flip it around on the first pass, otherwise risk losing the
next - We hold 2
*Nodepointers: oneprevto keep track of the previous node, so that we can connect back to it, and onetempto track thehead->next
// Initialise temp as nullptr
while (head != nullptr) {
temp = head->next; // save the next node
head->next = prev; // repoint next to the previous node
prev = head; // now the previous node is the head
head = temp; // head is the next
}