标签:链表
当代码试图访问空指针指向的内存时程序就会崩溃,从而导致鲁棒性问题。所以要对空链表单独处理。
ListNode* Merge(ListNode* pHead1, ListNode* pHead2)
{
if (pHead1 == NULL)
return pHead2;
else if (pHead2 == NULL)
return pHead1;
ListNode* pMergedHead = NULL;
if (pHead1->m_nValue < pHead2->m_nValue)
{
pMergedHead = pHead1;
pMergedHead->m_pNext = Merge(pHead1->m_pNext,pHead2);
}
else
{
pMergedHead = pHead2;
pMergedHead->m_pNext = Merge(pHead1, pHead2->m_pNext);
}
return pMergedHead;
}
版权声明:本文为博主原创文章,未经博主允许不得转载。
标签:链表
原文地址:http://blog.csdn.net/wangfengfan1/article/details/46805591