#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;
}
C++双重指针的区别
最新推荐文章于 2024-05-02 21:55:57 发布