void MergeList(LinkList &La, LinkList &Lb, LinkList &Lc)
{//有序链表的合并
pa = La->next; //pa和pb分别是链表La和Lb的工作指针,
pb = Lb->next; //分别初始化为相应链表的第一个结点
Lc = pc = La; //用La的头结点作为Lc的头结点
while (pa && pb)
{
if (pa->data < pb->data)
{
pc->next = pa;//将pa链接在pc后
pc = pa;
pa = pa->next;//pa指针后移
}
else if (pa->data > pb->data)
{//若Lb较小
pc->next = pb;//将pb链接在pc后
pc = pb;
pb = pb->next;//pb指针后移
}
else
{//若La==Lb
pc->next = pa;
pc = pa;
pa = pa->next;
q = pb->next;//接下来三行为删除Lb
delete pb;
pb = q;
}
}
pc->next = pa ? pa : pb; //插入剩余段
delete Lb; //释放Lb的头结点
}