做网站如何月入10万,建行app怎么注册登录,搭建个人视频网站,网站ui设计之道1、逆置链表#xff1a;前插法
void ReverseList(PSListNode* pHead)
{if (NULL *pHead){return;}else{//创建一个新的空链表#xff0c;遍历pHead指向的链表里的所有节点#xff0c;每找到一个#xff0c;就前插到新链表里PSListNode pNewHead *pHead;*pHead (*pHead)…1、逆置链表前插法
void ReverseList(PSListNode* pHead)
{if (NULL *pHead){return;}else{//创建一个新的空链表遍历pHead指向的链表里的所有节点每找到一个就前插到新链表里PSListNode pNewHead *pHead;*pHead (*pHead)-pNextNode;//第一次前插到新链表里的结点是新链表的尾节点所以要使它的下一个结点为空pNewHead-pNextNode NULL;while (NULL ! *pHead){PSListNode pNode *pHead;*pHead (*pHead)-pNextNode;pNode-pNextNode pNewHead;pNewHead pNode;}*pHead pNewHead;}
}
2、逆置链表三指针法
void ReverseList(PSListNode* pHead)
{assert(pHead);if ((*pHead NULL) || ((*pHead)-pNextNode) NULL){return;}else{PSListNode pPreNode *pHead;PSListNode pCurNode (*pHead)-pNextNode;PSListNode pOffNode (*pHead)-pNextNode-pNextNode;PSListNode pNode NULL;while (1){pCurNode-pNextNode pPreNode;pPreNode-pNextNode pNode;pNode pPreNode;if (pOffNode NULL){break;}else{pPreNode pCurNode;pCurNode pOffNode;pOffNode pOffNode-pNextNode;}}*pHead pCurNode;}
}