合并两个有序链表
ListNode* mergeTwoLists(ListNode* l1, ListNode* l2) {
ListNode node1(-1);
ListNode* head = &node1;
head->next = NULL;
ListNode* p = head;
if(NULL == l1 && NULL == l2)
{
return NULL;
}
if(NULL != l1 && NULL == l2)
{
return l1;
}
if(NULL == l1 && NULL != l2)
{
return l2;
}
while(NULL != l1 && NULL != l2)
{
if(l1->val > l2->val)
{
p->next = l2;
l2 = l2->next;
p = p-> next;
}
else
{
p->next = l1;
l1 = l1->next;
p = p-> next;
}
}
if(NULL == l1)
{
p -> next = l2;
}
if(NULL == l2)
{
p -> next = l1;
}
p = head -> next;
// free(head);
return p;
}