• + 1 comment

    Then ..this is simpler version:-

     SinglyLinkedListNode*temp;
    if(head1==NULL && head2==NULL){
        return NULL;
    }
    else if(head1!=NULL && head2==NULL){
        return head1;
    }
    else if(head1==NULL && head2!=NULL){
        return head2;
    }
    
    if(head1->data<=head2->data){
        temp=head1;
        temp->next= mergeLists(head1->next,head2);
    }
    else{
        temp=head2;
        temp->next= mergeLists(head1,head2->next);
    }
    
    return temp;