PLinkList Merge(PLinkList pList1, PLinkList pList2)
{
PLinkList pList;
PLinkList end;
if (pList1 == NULL)
{
return pList2;
}
if (pList2 == NULL)
{
return pList1;
}
if (pList1 == pList2)
{
return pList1;
}
// 摘一个节点做为新头节点
if (pList1->data < pList2->data)
{
pList = pList1;
pList1 = pList1->next;
}
else
{
pList = pList2;
pList2 = pList2->next;
}
end = pList;
while (pList1 && pList2)
{
Node* tmp;
if (pList1->data < pList2->data)
{
tmp = pList1;
pList1 = pList1->next;
}
else
{
tmp = pList2;
pList2 = pList2->next;
}
end->next = tmp;
end = tmp;
end->next = NULL;
}
if (pList1)
{
end->next = pList1;
}
if (pList2)
{
end->next = pList2;
}
return pList;
}
转载于:https://blog.51cto.com/10622551/1688436