🌈个人主页: 会编辑的果子君
💫个人格言:“成为自己未来的主人~”
以上是题目信息:
下面是解答过程
/*** Definition for singly-linked list.* struct ListNode {* int val;* struct ListNode *next;* };*/
typedef struct ListNode SListNode;
struct ListNode* mergeTwoLists(struct ListNode* list1, struct ListNode* list2) {SListNode*newHead,*newTail;SListNode* pcur=(SListNode*)malloc(sizeof(SListNode));newHead=newTail=pcur;SListNode*l1,*l2;l1=list1,l2=list2;if(l1==NULL){return l2;}if(l2==NULL){return l1;}while(l1 && l2){//l2小于l1if(l2->val < l1->val){newTail->next=l2;newTail=newTail->next;l2=l2->next;}//l1小于l2else{newTail->next=l1;newTail=newTail->next;l1=l1->next;}}if(l2==NULL){newTail->next=l1;}if(l1==NULL){newTail->next=l2;}return newHead->next;
}