版权声明:本文为博主原创文章,未经博主允许不得转载。 https://blog.csdn.net/guorong520/article/details/81254745
题目:将一个链表逆置
解析:使用三个指针,前、中、后,改变中指针,遍历后指针。
ListNode* ReverseList(ListNode* pHead)
{
if(pHead==NULL||pHead->next==NULL)
{
return pHead;
}
ListNode* pro=NULL;
ListNode* pCur=pHead;
ListNode* tail=pCur->next;
while(pCur->next)
{
pCur->next=pro;
pro=pCur;
pCur=tail;
tail=tail->next;
}
pCur->next=pro;
return pCur;
}