1个回答
展开全部
typedef int ElementType;
typedef struct Node *PtrToNode;//定义PtrToNode为指向Node的结构体指针
struct Node {
ElementType Data;
PtrToNode Next;
};
typedef PtrToNode List;//定义list为指向node结构体的指针
List Merge(List L1, List L2) {
List pa = L1,pb = L2,head;
List head = pc = (struct Node *)malloc(sizzeof(struct Node));
pc = (pa->Data <= pb->Data) ? pa : pb; //pc指向Data较小的节点
while (pa && pb) { //循环比较L1与L2两条链表的Data
if (pa->Data < pb->Data) {
pc->Next = pa;
pc = pc->Next;
pa = pa->Next;
}
else {
pc->Next = pb;
pc = pc->Next;
pb = pb->Next;
}
}
while(pa) { pc->Next = pa; pc = pc->Next; pa = pa->Next; }//将剩余的链表接到pc后面
while(pb) { pc->Next = pb; pc = pc->Next; pb = pb->Next; }
printf("List Merge is available!");
return head;
}
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询