topic
Define a function that takes as input the head node of a linked list, reverses the linked list and outputs the head node of the reversed linked list.
Python problem solving
def reverse_list(head):
q = None
p = head
reverse_head = None
while p:
r = p.next
if r is None:
reverse_head = p
p.next = q
q = p
p = r
return reverse_head