面试题25:合并两个排序的链表
题目:输入两个递增排序的链表,合并这两个链表并使新链表中的结点仍然是按照递增排序的。例如输入图3.11中的链表1和链表2,则合并之后的升序链表如链表3所示。
#include <iostream>
#include <algorithm>
#include <cmath>
#include <cstring>
using namespace std;
struct ListNode{
int value;
ListNode* next;
};
ListNode* Merge(ListNode* pHead1, ListNode* pHead2){
if(pHead1==NULL) return pHead2;
if(pHead2==NULL) return pHead1;
ListNode* pMergeHead=NULL;
if(pHead1->value<pHead2->value){
pMergeHead=pHead1;
pMergeHead->next=Merge(pHead1->next, pHead2);
}else{
pMergeHead=pHead2;
pMergeHead->next=Merge(pHead1, pHead2->next)
}
return pMergeHead;
}
int main() {
return 0;
}