作者:手机用户2502903481 | 来源:互联网 | 2023-10-11 12:54
voidmerge(LNode*A,LNode*B,LNode*&C)*&C是新链表{待对比的指针*p,*qLNode*pA-next;LNode*qB-next;LNode*
void merge(LNode *A, LNode *B, LNode *&C) // *&C是新链表
{
//待对比的指针 *p, *q
LNode *p = A->next;
LNode *q = B->next;
LNode *s;
//只要其中一个头节点,然后将另外的释放
C = A;
C->next = NULL;
free (B);
while(p != NULL && q != NULL)
{
if(p->data <= q->data)
{
s = p; p = p->next;
s->next = C->next; C->next = s;
}
else
{
//改为头插法
s = q; q = q->next;
s->next = C->next; C->next = s;
}
}
if(p != NULL)
{
s = p;
p = p->next;
s->next = C->next;
C->next = s;
}
if(q != NULL)
{
s = q;
q = q->next;
s->next = C-next;
C->next = s;
}
}