• + 2 comments

    My code, which passes all tests:

    Node* MergeLists(Node *headA, Node* headB)
    {   
        if(!headA)
            return headB;
        if(!headB)
            return headA;
        if(headA->data > headB->data){
            headB->next = MergeLists(headA, headB->next);
            return headB;
        }
        else{
            headA->next = MergeLists(headA->next, headB);
            return headA;
        }
    }
    

    Tip: recursion can be by itself confusing, so writing less code, keeps confusion out of the way ;)

    • + 0 comments

      Hey @whoiscris can u pls explain how does the code work?? I'm stuck by the recursion part here :( i don't get it right

    • + 0 comments

      Can you please explain your code by taking an example?? I am new to recursion.