![在这里插入图片描述](https://img-blog.csdnimg.cn/7c557f90857647d29150b60abc62f579.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;
}