List Merge( List L1, List L2 ){
struct Node *h,*p,*l1,*l2;
h = (struct Node*)malloc(sizeof(struct Node));
h->Next = NULL;
p = h;
l1 = L1->Next;
l2 = L2->Next;
while(l1!=NULL && l2!=NULL){
if(l1->Data > l2->Data){
p->Next = l2;
p = l2;
l2 = l2->Next;
}
else if(l1->Data <= l2->Data){
p->Next = l1;
p = l1;
l1 = l1->Next;
}
//else{
// p->Next = l1;
// p = l1;
// l1 = l1->Next;
// l2 = l2->Next;
//}
}
while(l1==NULL && l2!=NULL){
p->Next = l2;
p = l2;
l2 = l2->Next;
}
while(l1!=NULL && l2==NULL){
p->Next = l1;
p = l1;
l1 = l1->Next;
}
p->Next = NULL;
L1->Next = NULL;
L2->Next = NULL;
return h;
}
1. 链表合并以后,相同的元素应该都放在链表中,而不应该保存为一个值。