You are viewing a single comment's thread. Return to all 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 ;)
Seems like cookies are disabled on this browser, please enable them to open this website
Merge two sorted linked lists
You are viewing a single comment's thread. Return to all comments →
My code, which passes all tests:
Tip: recursion can be by itself confusing, so writing less code, keeps confusion out of the way ;)