分类: C/C++
2015-05-12 17:37:18
if ( head1 == NULL )
return head2 ;
if ( head2 == NULL)
return head1 ;
Node *head = NULL ;
if ( head1->data < head2->data )
{
head = head1 ;
head->next = MergeRecursive(head1->next,head2);
}
else
{
head = head2 ;
head->next = MergeRecursive(head1,head2->next);
}
return head ;
}
Node *tmp=head;
while(NULL != head1 && NULL != head2)
{
if(head1->data
{
tmp->next=head1;
tmp=head1;
head1=head1->next;
}
else
{
tmp->next=head2;
tmp=head2;
head2=head2->next;
}
}
if(NULL != head1)
{
tmp->next=head1;
}
if(NULL != head2)
{
tmp->next=head2;
}
return tmp;
}