![在这里插入图片描述](https://i-blog.csdnimg.cn/blog_migrate/1cfd2429637757d628c001e80a6731b7.png)
迭代法
struct ListNode* ReverseList(struct ListNode* pHead ) {
if(pHead == NULL || pHead->next == NULL)
return pHead;
struct ListNode* node_before = NULL;
struct ListNode* node = pHead;
struct ListNode* node_after = pHead->next;
while(1){
node->next = node_before;
if(node_after == NULL)
break;
node_before = node;
node = node_after;
node_after = node_after->next;
}
pHead = node;
return pHead;
}
递归法
struct ListNode* ReverseList(struct ListNode* pHead ) {
if(pHead == NULL || pHead->next == NULL)
return pHead;
struct ListNode* newHead = ReverseList(pHead->next);
pHead->next->next =pHead;
pHead->next = NULL;
return newHead;
}