第一种方法:普通方法
void reverseList(pNode *head)
{
pNode p, q, r;
if (*head == NULL || (*head)->next == NULL)
return;
q = *head;
p = q->next;
r = NULL;
while (p) {
q->next = r;
r = q;
q = p;
p = p->next;
}
q->next = r;
*head = q;
}
第二种方法:递归实现
pNode reverseList_reverse(pNode head)
{
pNode current_head, head_next;
if (head == NULL)
return NULL;
if (head->next == NULL) {
return head;
}else {
current_head = head;
head_next = head->next;
head = reverseList_reverse(head_next);
head_next->next = current_head;
current_head->next = NULL;
}
return head;
}