题目:定义一个函数,输入一个链表的头结点,反转该链表并输出反转后链表的头结点。
参考代码:
void ReverseList(pList *pHead)
{
pLinkList cur=*pHead;
pLinkList prev=NULL;
pLinkList pNewHead=NULL;
assert(pHead);
if(cur==NULL)
{
return;
}
if(cur->next==NULL)
{
return;
}
while(cur)
{
prev=cur;
cur=cur->next;
prev->next=pNewHead;
pNewHead=prev;
}
*pHead=pNewHead;
}本文出自 “七月朔风” 博客,请务必保留此出处http://luminous.blog.51cto.com/10797288/1743503
原文:http://luminous.blog.51cto.com/10797288/1743503