链表翻转

ListNode* ReverseList(ListNode* pHead)
{
if (pHead == NULL)
{
return NULL;
}

ListNode pHeadNew(0);
pHeadNew.next = pHead;

ListNode* curNode = pHead;
ListNode* nextNode = pHead->next;
while (nextNode != NULL)
{
curNode->next = nextNode->next;
nextNode->next = pHeadNew.next;
pHeadNew.next = nextNode;
nextNode = curNode->next;
}

return pHeadNew.next;
}

上一篇:C语言构建一个链表以及操作链表


下一篇:数据结构3--带头节点的双向循环链表