1:链表倒序
ListNode* reverseList(ListNode* head)
{
ListNode *p1, *p2 , *p3;
//链表为空,或是单结点链表直接返回头结点
if (head == NULL || head->next == NULL)
{
return head;
}
p1 = head;
p2 = head->next;
while (p2 != NULL)
{
p3 = p2->next;
p2->next = p1;
p1 = p2;
p2 = p3;
}
head->next = NULL;
head = p1;
return head;
}
阅读(473) | 评论(0) | 转发(0) |