In linked list problems, you generally cannot directly change the value of nodes.
Using the head insertion method to reverse a linked list, creating a dummy head node can avoid some special cases. Also, at the end, you should not return head, but virt_head->next, because head may change due to swapping.