您好,登录后才能下订单哦!
// 合并两个已序单链表
PSListNode MergeList(PSListNode pL1, PSListNode pL2)
{
PSListNode pNewHead = NULL ;
PSListNode pL1Node = pL1 ;
PSListNode pL2N0de = pL2 ;
PSListNode pNode = NULL ;
PSListNode pTailNode = NULL ;
if (pL1 == NULL)
{
return pL2 ;
}
if (pL2 == NULL)
{
return pL1 ;
}
if (pL1Node->data > pL2N0de->data)
{
pNode = pL2N0de;
pL2N0de = pL2N0de->pNext;
}
else
{
pNode = pL1Node;
pL1Node = pL1Node->pNext;
}
pNewHead = pNode;
pTailNode = pNode;
while (pL1Node&&pL2N0de)
{
if (pL1Node->data > pL2N0de->data)
{
pNode = pL2N0de;
pL2N0de = pL2N0de->pNext;
}
else
{
pNode = pL1Node;
pL1Node = pL1Node->pNext;
}
pTailNode->pNext = pNode;
pTailNode = pTailNode->pNext;
}
if (pL1Node == NULL )
{
pTailNode->pNext = pL2N0de;
}
else
{
pTailNode->pNext = pL1Node;
}
return pNewHead;
}
void Print(PSListNode pHead)
{
PSListNode pCurNode = pHead ;
while (pCurNode)
{
printf( "%d->", pCurNode->data);
pCurNode = pCurNode->pNext;
}
printf( "NULL\n");
}
免责声明:本站发布的内容(图片、视频和文字)以原创、转载和分享为主,文章观点不代表本网站立场,如果涉及侵权请联系站长邮箱:is@yisu.com进行举报,并提供相关证据,一经查实,将立刻删除涉嫌侵权内容。