• + 0 comments

    On similar lines

    SinglyLinkedListNode n=head1;

    if((head1==null)&&(head2==null))

    {

    return null;

    }

    if((head1!=null)&&(head2==null))

    {

    return head1;

    }

    if((head1 == null)&&(head2!=null))

    {

    return head2;

    }

    if(head1.data <= head2.data)

    {
    head1.next = mergeLists(head1.next, head2);

    n=head1;

    }

    else if(head1.data > head2.data)

    {

    head2.next = mergeLists(head2.next, head1);

    n=head2;

    } return n;
    }