Node* invert_list(Node* phead)
{
if(phead==NULL || phead->pNext==NULL)//参数验证
return phead;
Node* p1=phead;
Node* p2=phead->pNext;
Node* p3=phead->pNext->pNext;
while(p2!=NULL)
{
p2->pNext=p1;
p1=p2;
p2=p3;
if(p3!=NULL)//到最后p3为空。因此p3->pNext时需要小心。
p3=p3->pNext;
}
phead->pNext=NULL;
return p1;
}
Node* invert_list_recu(Node* phead)
{
if(phead==NULL || phead->pNext==NULL)
return phead;
Node* pnext=phead->pNext;
Node* pheadnew=invert_list_recu(pnext);
pnext->pNext=phead;
return pheadnew;
}