只是提供思路,缺少很多边界条件的检查
/* 递归法实现有序单链表的合并 */
LinkedList *MergeRecursive(LinkedList *head1, LinkedList *head2)
{
if (head1 == NULL)
return head2;
if (head2 == NULL)
return head1;
LinkedList *head = NULL;
if (head1->iValue < head2->iValue)
{
head = head1;
head->next = MergeRecursive(head1->next, head2);
}
else
{
head = head2;
head->next = MergeRecursive(head1, head2->next);
}
return head;
}