题解
合并两个有序的单链表
http://www.nowcoder.com/questionTerminal/98a51a92836e4861be1803aaa9037440
list_node * merge_list(list_node * head1, list_node * head2) { //////在下面完成代码 list_node* res= new list_node(); list_node* cur= res; while(head1 != nullptr && head2 != nullptr) { if(head1->val < head2->val) { list_node* tmp= new list_node(); tmp->val = head1->val; tmp->next =nullptr; cur->next = tmp; cur = tmp; head1 = head1->next; } else if(head1->val >= head2->val) { list_node* tmp= new list_node(); tmp->val = head2->val; tmp->next =nullptr; cur->next = tmp; cur = tmp; head2 = head2->next; } } if(head1 != nullptr) cur->next = head1; if(head2 != nullptr) cur->next = head2; return res->next; }