#include<cstdlib>
struct ListNode
{
int m_value;
ListNode *m_pnext;
}
void AddtoTail(ListNode **phead,int value)) /*之所以用**phead,只因为如果用*phead只是调用头指针的副本,但函数结束后副本会被摧毁,头指针没有变化。但当链表为空时,增加结点会改变头指针,当用*phead会导致头指针一直为空*/
{
ListNode *pnew = new ListNode();
pnew->m_value = value;
pnew->m_pnext = NULL;
if(*phead == NULL)
*phead = pnew;
else
{
ListNode *pnode = *phead;
while(pnode->m_pnext != NULL)
pnode = pnode->m_pnext;
pnode->m_pnext = pnew;
}
}