版权声明:本文为博主原创文章,遵循 CC 4.0 BY-SA 版权协议,转载请附上原文出处链接和本声明。
#include <iostream>
using namespace std;
struct ListNode
{
int m_nValue;
ListNode* m_pNext;
};
void AddToTail(ListNode** pHead, int val)
{
ListNode* pNew = new ListNode();
pNew->m_pNext = nullptr;
pNew->m_nValue = val;
if (*pHead == nullptr)
{
*pHead = pNew;
}
else
{
ListNode* pNode = *pHead;
while (pNode->m_pNext != nullptr)
pNode = pNode->m_pNext;
pNode->m_pNext = pNew;
}
}
void AddToTail(ListNode* pHead, int val)
{
ListNode* pNew = new ListNode();
pNew->m_pNext = nullptr;
pNew->m_nValue = val;
if (pHead == nullptr)
{
pHead = pNew;
}
else
{
ListNode* pNode = pHead;
while (pNode->m_pNext != nullptr)
pNode = pNode->m_pNext;
pNode->m_pNext = pNew;
}
}
int main()
{
ListNode* p_nullptr = nullptr;
ListNode** p_p_nullptr = &p_nullptr;
AddToTail(p_nullptr, 100);
return 0;
}