struct ListNode* mergeTwoLists(struct ListNode* l1,struct LisNOde* l2){
//如果其中一个链表为空,返回另一个
if(l1==NULL)
return l2;
if(l2==NULL)
return l1;
struct LIstNOde* head=NULL,*tail=NULL;
while(l1 && l2)
{
if(l1->val<l2->val)
{
//尾插
if(head==NULL)
{
head=tail=l1;
}
else
{
tail->next=l1;
tail=l1;
}
l1=l1->next;
}
else
if(head==NUll)
{
{
head=tail=l2;
}
else
{
tail->next=l2;
tail=l2;
}
l2=l2->next;
}
}
if(l1)
{
tail->next=l1;
}
if(l2)
{
tail->next=l2;
}
return head;
}