2 u010814878 u010814878 于 2013.10.01 18:29 提问

如何用递归算法实现2个有序链表的合并?

stu* Combine(stu* head1, stu* head2)
{

if (head1 == NULL)
{
    return head2;
}
if (head2 == NULL)
{
    return head1;
}
stu* head = NULL;
if (head1->m_score < head2->m_score)
{
    head = head2;
    head->next = Combine(head1,head2->next);
}
else
{
    head = head1;
    head->next = Combine(head1->next, head2);
}
return head;

}

Csdn user default icon
上传中...
上传图片
插入图片