标签:rev lis 反转 col next null list == div
题目:输入一个链表,反转链表后,输出链表的所有元素
思路:使用三个指针遍历一遍链表
注意:代码的鲁棒性!
ListNode* ReverseList(ListNode* pHead) { if(pHead == NULL)return NULL; if(pHead->next == NULL)return pHead; ListNode* p1 = NULL; ListNode* p2 = NULL; ListNode* p3 = NULL; p2 = pHead; p3 = pHead->next; while(p3 != NULL) { p2->next = p1; p1 = p2; p2 = p3; p3 = p3->next; } p2->next = p1; return p2; }
标签:rev lis 反转 col next null list == div
原文地址:https://www.cnblogs.com/yapp/p/9068585.html