代码:
/**
* Definition for singly-linked list.
* struct ListNode {
* int val;
* ListNode *next;
* ListNode(int x) : val(x), next(NULL) {}
* };
*/
class Solution {
public:
ListNode* mergeTwoLists(ListNode* l1, ListNode* l2) {
ListNode *now=NULL,**tmp=&now;
/// **tmp表示now指针的地址
/// *tmp 表示指针指向&now这个地址
while(l1 || l2){
if(l1==NULL || (l2 && l1->val > l2->val) ){
*tmp=l2;
l2=l2->next;
} else {
*tmp=l1;
l1=l1->next;
}
tmp=&((*tmp)->next);
}
return now;
}
};