逆转链表 删除链表非尾节点

void deleteNotTailNode(PNode &pHead, PNode pNode)
{
if (pNode == nullptr || pHead == nullptr)
return;
if (pNode == pHead)
{
pHead = pHead->_pNext;
delete pNode;
}
else
{
Node* pTemp = pNode->_pNext;
pNode->_data = pTemp->_data;
pNode->_pNext = pTemp->_pNext;
delete pTemp;
}
}
void PrintReverse(PNode pNode)
{
if (pNode)
{
PrintReverse(pNode->_pNext);
cout << pNode->_data << " ";
}
}

复制复杂链表

void CloneNode(ListNode *pHead)
{
ListNode *pNode = pHead;
while (pNode != nullptr)
{
ListNode *pCloned = new ListNode;
pCloned->_data = pNode->_data;
pCloned->_pNext = pNode->_pNext;
pCloned->_pSibling = nullptr;
pNode->_pNext = pCloned;
pNode = pCloned->_pNext;
}
}
void CloneSibling(ListNode *pHead)
{
ListNode *pNode = pHead;
while (pNode != nullptr)
{
ListNode *pCloned = pNode->_pNext;
if (pNode->_pSibling != nullptr)
{
pCloned->_pSibling = pNode->_pSibling->_pNext;
}
pNode = pCloned->_pNext;
}
}
ListNode *DivideList(ListNode *pHead)
{
ListNode *pNode = pHead;
ListNode *pCloneHead = nullptr;
ListNode *pCloneNode = nullptr;
if (pNode != nullptr)
{
pCloneHead = pNode->_pNext;
pNode->_pNext = pCloneHead->_pNext;
pNode->_pNext = pNode->_pNext;
}
while (pNode != nullptr)
{
pCloneNode->_pNext = pNode->_pNext;
pCloneNode = pCloneNode->_pNext;
pNode->_pNext = pCloneNode->_pNext;
pNode = pNode->_pNext;
}
return