您好,登錄后才能下訂單哦!
// 合并兩個已序單鏈表
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進行舉報,并提供相關證據,一經查實,將立刻刪除涉嫌侵權內容。