List * Reverse(List * pHead)
{
if(pHead==NULL||pHead->pNext==NULL) return pHead; //链表小于2不用反转
List *p ,r, q; //定义三个指针
p = pHead;
r = pHead->pNext;
pHead ->pNext = NULL; //一个指向头,一个标记头的下一个,然后把头指针指向空
while(r)
{
q= r->pNext;
r->pNext = p;
p=r;
r=q;
}
pHead = p;
return pHead;
}
C++ 手写单链表反转(ReverseList)头插法
最新推荐文章于 2022-12-05 20:11:32 发布